GDGraph
view release on metacpan or search on metacpan
Graph/colour.pm view on Meta::CPAN
@{$rgb_ref};
}
=head2 _hue( I<R,G,B> )
Returns the hue of the colour with the specified RGB values.
Exported with the :colours tag.
=head2 _luminance( I<R,G,B> )
Returns the luminance of the colour with the specified RGB values.
Exported with the :colours tag.
=cut
# return the luminance of the colour (RGB)
sub _luminance
{
(0.212671 * $_[0] + 0.715160 * $_[1] + 0.072169 * $_[2])/0xFF
}
# return the hue of the colour (RGB)
sub _hue
{
($_[0] + $_[1] + $_[2])/(3 * 0xFF)
}
=head2 add_colour(colourname => [$r, $g, $b]) or
add_colour('#7fe310')
Self-explanatory.
Exported with the :colours tag.
=cut
sub add_colour
{
my $name = shift;
my $val = shift;
if (!defined $val)
{
my @rgb = hex2rgb($name) or return;
$val = [@rgb];
}
if (ref $val && ref $val eq 'ARRAY')
{
$RGB{$name} = [@{$val}];
return $name;
}
return;
}
=head2 rgb2hex($red, $green, $blue)
=head2 hex2rgb('#7fe310')
These functions translate a list of RGB values into a hexadecimal
string, as is commonly used in HTML and the Image::Magick API, and vice
versa.
Exported with the :convert tag.
=cut
# Color translation
sub rgb2hex
{
return unless @_ == 3;
my $color = '#';
foreach my $cc (@_)
{
$color .= sprintf("%02x", $cc);
}
return $color;
}
sub hex2rgb
{
my $clr = shift;
my @rgb = $clr =~ /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
return unless @rgb;
return map { hex $_ } @rgb;
}
=head2 read_rgb( F<file name> )
Reads in colours from a rgb file as used by the X11 system.
Doing something like:
use GD::Graph::bars;
use GD::Graph::colour;
GD::Graph::colour::read_rgb("rgb.txt") or die "cannot read colours";
Will allow you to use any colours defined in rgb.txt in your graph.
Exported with the :files tag.
=cut
#
# Read a rgb.txt file (X11)
#
# Expected format of the file:
#
# R G B colour name
#
# Fields can be separated by any number of whitespace
# Lines starting with an exclamation mark (!) are comment and
# will be ignored.
#
# returns number of colours read
sub read_rgb($) # (filename)
{
my $fn = shift;
my $n = 0;
my $line;
( run in 2.212 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )