NAME
Chart::Color::Constant - access values of color constants
SYNOPSIS
my @names = Chart::Color::Constant::all_names();
my @rgb = Chart::Color::Constant::rgb_from_name('darkblue');
my @hsl = Chart::Color::Constant::hsl_from_name('darkblue');
Chart::Color::Value::add_rgb('lucky', [0, 100, 50]);
DESCRIPTION
RGB and HSL values of named colors from the X11 and HTML standard and Pantone report. Allows also reverse search, storage and conversion of color values.
This module is supposed to be used by Chart::Color and not directly by the user (for the most part). It converts a stored color name into its values (rgb, hsl or both) and back. One color can have multiple names. Also nearby (similar) colors can be searched. Own colors can be (none permanently) stored for later reference by name. For this a name has to be chosen, that is not already taken. Independently of that can any color be converted from rgb to hsl and back.
ROUTINES
rgb_from_name
Red, Green and Blue value of the named color. These values are integer in 0 .. 255.
my @rgb = Chart::Color::Constant::rgb_from_name('darkblue');
@rgb = Chart::Color::Constant::rgb_from_name('dark_blue'); # same result
@rgb = Chart::Color::Constant::rgb_from_name('DarkBlue'); # still same
hsl_from_name
Hue, saturation and lightness of the named color. These are integer between 0 .. 359 (hue) or 100 (sat. & light.). A hue of 360 and 0 (degree in a cylindrical coordinate system) is considered to be the same, this modul deals only with the ladder.
my @hsl = Chart::Color::Constant::hsl_from_name('darkblue');
name_from_rgb
Returns name of color with given rgb value triplet. Returns empty string if color is not stored. When several names define given color, the shortest name will be selected in scalar context. In array context all names are given.
say Chart::Color::Constant::name_from_rgb( 15, 10, 121 ); # 'darkblue'
say Chart::Color::Constant::name_from_rgb([15, 10, 121]); # works too
name_from_hsl
Returns name of color with given hsl value triplet. Returns empty string if color is not stored. When several names define given color, the shortest name will be selected in scalar context. In array context all names are given.
say scalar Chart::Color::Constant::name_from_hsl( 0, 100, 50 ); # 'red'
scalar Chart::Color::Constant::name_from_hsl([0, 100, 50]); # works too
say for Chart::Color::Constant::name_from_hsl( 0, 100, 50 ); # 'red', 'red1'
names_in_hsl_range
Color names in selected neighbourhood of hsl color space, that look similar. It requires two arguments. The first one is an array containing three values (hue, saturation and lightness), that define the center of the neighbourhood (searched area).
The second argument can either be a number or again an array with three values (h,s and l). If its just a number, it will be the radius r of a ball, that defines the neighbourhood. From all colors inside that ball, that are equal distanced or nearer to the center than r, one name will returned.
If the second argument is an array, it has to contain the tolerance (allowed distance) in h, s and l direction. Please note the h dimension is circular: the distance from 355 to 0 is 5. The s and l dimensions are linear, so that a center value of 90 and a tolerance of 15 will result in a search of in the range 75 .. 100.
The results contains only one name per color (the shortest).
# all bright red'ish clors
my @names = Chart::Color::Constant::names_in_hsl_range([0, 90, 50], 5);
# approximates to :
my @names = Chart::Color::Constant::names_in_hsl_range([0, 90, 50],[ 3, 3, 3]);
all_names
A sorted list of all stored color names.
name_taken
A perlish pseudo boolean tells if the color name is already in use.
add_rgb
Adding a color to the store under an not taken (not already used) name. Arguments are name, red, green and blue value (integer < 256, see rgb).
Chart::Color::Constant::add_rgb('nightblue', 15, 10, 121 );
Chart::Color::Constant::add_rgb('nightblue', [15, 10, 121]);
add_hsl
Adding a color to the store under an not taken (not already used) name. Arguments are name, hue, saturation and lightness value (see hsl).
Chart::Color::Constant::add_rgb('lucky', 0, 100, 50 );
Chart::Color::Constant::add_rgb('lucky', [0, 100, 50]);
COPYRIGHT & LICENSE
Copyright 2022 Herbert Breunung.
This program is free software; you can redistribute it and/or modify it under same terms as Perl itself.
AUTHOR
Herbert Breunung, <lichtkind@cpan.org>