Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

acme
  (email not shown publicly)
http://www.astray.com/

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Friday February 22, 2002
08:19 AM

Acme::Colour

[ #3034 ]
Amongst all the Pipeline discussions we've been having recently, I've been trying to come up with realworld-like examples. One example was a Pipeline which has a Tap at the beginning and end, through which flows Water objects. Occasionally, there are Segments in the Pipe which can dye the water going past it a particular colour. I thought this was quite a good example, and Pipeline currently ships with it as a test.

However, it isn't quite like real world, as if you start dyeing the water multiple times, say, "red" and then "green" it doesn't behave in real life. It just says the water is "greenish red". What I needed was a way to model additive and subtractive colour mixing which results in human-readable colours... enter Acme::Colour!

The module takes in colour names, mixes in other colours (either as light or as paint) and returns a colour name. So black with red and green makes yellow if dealing with light, or white plus cyan and magenta makes green if dealing with paint.

The actual colour mixing wasn't the hard part (I got colour values from Graphics::ColorNames). The hard part was returning a colour name. I didn't want to know the red, green and blue values of the resulting colour but rather that it was "dark red". So I get the RGB values and go through every named colour that I know and find the closest match in 3D RGB space. Hey presto: named colours to named colours.

Taken straight from the tests:

$c = Acme::Colour->new("orange");
ok($c, "should get colour");
is("$c", "orange", "should get orange");
$c->mix("brown");
is("$c", "dark red", "orange and brown is dark red");

Now all I need to do is make a better pipeline example...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.