Color::Mix - Generate themes from an RGB color wheel.
my $color = Color::Mix->new; # Complementary to red my $complementary_color = $color->complementary('ff0000'); # Double complementary to red/yellow my ($color1, $color2) = $color->double_complementary('ff0000', 'ffff00'); my ($color1, $color2) = $color->double_complementary('red', 'yellow'); # Generate a default analogous color scheme for red my @analogous = $color->analogous('ff0000'); # Generate a more controlled analogous color scheme for blue # Give me 5 colors, slice the color wheel up into 36. # The defaults are 3 colors + the one passed in, 12 slices. my @analogous = $color->analogous('0000ff', 5, 36);
Color::Mix is a lightweight color scheme generator for Perl. Users of this module are expected to know how to use RGB hexidecimal colors.
All the scheme methods take at the very minimum either an rgb hex code for the color you are trying to calculate or a color name from the common X11 color list. In addition to this the analogous method can take a number of arguments to gain fine grained control over the scheme generated through controlling the color range.
The colors are calculated against an RGB color wheel internally.
Note: This module uses Red, Green and Blue for it's primary colours which differs from the normal color theory of Red, Yellow and Blue. What this means is it uses HSV-to-RGB to calculate the schemes so should behave in the same way as the color wheel in popular image manipulation apps like Gimp & Photoshop.
This module doesn't have any dependencies and should run on any modern-ish version of Perl 5. Tested on 5.8
my $color = Color::Mix->new();
Create a new instance of the Color::Mix class;
my $complementary_color = $color->complementary('ff0000');
Given a hex color code as a parameter the complementary() method returns a hexidecimal color of the parameters complement. A complimentary color is one who is on the opposite side of the color wheel in this case an RGB color wheel.
When mixed togther the two colours should produce a grey if the colors are complementary. An easy way to test this is to use the Blend Tool in Gimp.
my ($color1, $color2) = $color->double_complementary('ff0000', 'ffff00');
Given two hexadecimal color codes as parameters, this method calculates both their complements and returns them in an array.
my @analogous = $color->analogous('0000ff', 5, 36);
Analogous color schemes are ones in which the colors lie next to each other on the color wheel.
By default this method splits up the colorwheel into 12 pieces and returns the next 3 pieces of the wheel. So using this if you entered 0000ff (blue) then by default you would get back '80000ff' (purple), 'ff00ff' (pink) and 'ff0080' (hotpink) colors.
If you split the wheel up into 36 as in the example above you essentially reduce the range of the colors by 3. So now if you entered 0000ff (blue) but added a parameter 3 (For number of colors you want returned) and 36 (To split the wheel up into 36 pieces) then you would get back '2b00ff' (Blue), '5500ff' (Bluey Purple) and '8000ff' (Purple).
This gives and easy way to either limit or expand the range of the analogous color palette.
my @trinary = $color->trinary('ff0000'); my @trinary = $color->trinary('limegreen');
Given a hexidecimal color the trinary method will calculated two other colors that are evenly spaced around the RGB color wheel.
So for the example given above where red is passed into the method the results would be 'ff0000' (Red), '00ff00' (Green), '0000ff' (Blue).
If you want three really different colours for your web site/app then this method is a good one to use.
my $lightened = $color->lighten('660000'); my $lightened = $color->lighten('darkred'); my $lightened = $color->lighten('660000', 2);
The lighten method will take a given color and increase the value of each of the RGB components of the color by 32 (default).
If a second parameter is present it will use this and multiply the 32 by it. So in the second example above it will increase each of the RGB components by 32 x 2 = 64. When the value of any of the RGB components gets to 255 it stops increasing it's value.
This method is useful if one of the colors generated by any of the methods above is a little too dark for your liking, just pass the color to the lighten method to get a lighter version.
my $darkened = $color->darken('ffff00'); my $darkened = $color->darken('yellow'); my $darkened = $color->darken('ffff00', 2);
In opposite to the lighten method above, the darken method will take a given color and decrease each of it's RGB components by 32 in it's default setting.
If a second parameter is present it will use this and multiply the 32 by it. So in the second example above it will decrease each of the RGB components by 32 x 2 = 64. When the value of any of the RGB components is at 0, it will not decrease it's value any more.
I find this method useful to generate borders when I know the background color, you can get a yellow background, with a dark gold colored border just by passing the yellow color into the darken method.
my $hex = $color->get_color('limegreen'); # hex will be 32cd32
If given a valid color name from the W3C X11 Colors list (Which is the same as the SVG 1.0 color list, return the RGB hex for the given color name. If a valid hex RGB number is given as a parameter it just returns it.
my @colors = $color->get_color_list;
This returns the valid list of named colors known to Color::Mix. The list was generated from W3C sites listing of X11 colors which are the same as the SVG 1.0 color list.
This alters the behavious of both the lighten and darken methods. By default Color::Mix makes this value 32 decimal which changes 000000 to 202020 using the lighten method. If we set the shade value to 1 decimal then making the same call would lighten 000000 to 010101.
my $current_shade = $color->get_shade;
This method returns the current shade value that is being used. The default is 32, but can be changed by calling the set_shade method described above.
Color::Scheme if you want your schemes generated by Red, Yellow, Blue instead of the css based Red, Green, Blue.
Lee Dalton <email@example.com>
Copyright (C) 2009 by Lee Dalton.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.