Color

Translate, lighten, darken, invert named colors.

PhilipRBrenan@yahoo.com, 2004, Perl License

Synopsis

Example t/color.t

#_ Color _______________________________________________________________
# Test colors
# philiprbrenan@yahoo.com, 2004, Perl License    
#_______________________________________________________________________

use Math::Zap::Color;
use Test::Simple tests=>20;

ok(color('dark red')->normal eq '#8b0000');
ok(color('dark red')->light  eq '#c58080');
ok(color('red')->normal      eq '#ff0000');
ok(color('red')->light       eq '#ff8080');
ok(color('red')->dark        eq '#7f0000');
ok(color('red')->invert      eq '#00ffff');

use Math::Zap::Color color=>'c', invert=>-i;

my $c = c -red;
ok("$c"                  eq '#ff0000');
ok(i(-red)               eq '#00ffff');
ok(c('dark red')->normal eq '#8b0000');
ok(c('dark red')->light  eq '#c58080');
ok($c->normal            eq '#ff0000');
ok($c->light             eq '#ff8080');
ok($c->dark              eq '#7f0000');
ok($c->invert            eq '#00ffff');
ok(c(-green)             eq '#00ff00');
ok(c('ReD')              eq '#ff0000');
ok(c(-red)               eq '#ff0000');
ok(c('#ff0000')          eq '#ff0000');
ok(c('ff0000')           eq '#ff0000');
ok(c('255,0,0')          eq '#ff0000');

Description

Simplifies the management of colors by allowing X11 color names to be used; provides methods for manipulating the colors.

Constructors

color

A color may be constructed from a reference to an existing color, or from a string containing: a color name (quoted or preceeded by -, case insensitive), or 3 hexadecimal numbers optionally preceeded by #, or 3 decimal numbers separated by commas: these number representing the rgb color values in the range 0..255. Thus:

'ReD'
-red
'ff0000'
'255,0,0'

Methods

check

Check that an anonymous reference is a reference to a color and confess if it is not.

is

Same as "check" but return the result to the caller.

normal

Normal value of the color

light

Lighter shade of the color

dark

Darker shade of the color

invert

Inversion of the color

Color table

The names of the colors and their matching RGB values.

Operator Overloads

Stringification returns the normal value of the color

Exports

Export "color", "light", "dark", "invert"

Credits

Author

philiprbrenan@yahoo.com

philiprbrenan@yahoo.com, 2004

License

Perl License.