Acme::Colour

acme on 2002-02-22T13:19:28

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...


Being Inclusive

chromatic on 2002-02-22T18:46:54

Can I write Acme::Colour::Blind? I know the difference between additive and subtractive. All that's left is to figure out dozens of ways to say "a somewhat lighter shade of gray" and "something darker than before".

Damian has a paper on this...

pne on 2002-02-23T10:09:51

Are you aware of Damian Conway's paper on "natural language generation of colour names"?

Re:Damian has a paper on this...

acme on 2002-02-23T10:16:41

No, I hadn't seen that. Pretty cool ;-)