Gonna post a bit of code on my companies blog... but wanna make sure there's no obvious mistakes in it before I do. If anyone gets the time and knows a bit of javascript, would they might having a quick look over it? I'm not expecting it to be perfect, just 'not shit'.
The basis behind it is that you can do this:
javascript code:
var color = new Hex(‘000000’).toRGB(); // outputs 0,0,0
and you can string converts together, so you can do this..
javascript code:
var color = new Hex(‘cc0000’).toRGB().toCMYK().toCIELab();
Each color object also has a “websafe()” function, which’ll convert it to a websafe color… like this..
javascript code:
var color = new Hex(‘112233’).websafe();
or...
javascript code:
var color = new Hex(‘112233’).websafe().toRGB();
I’ve also written in a bit of color matching so that you can pass it a pallet of colours and it’ll return the nearest match, like this:
javascript code:
var color = new Hex(’225577’).match ([
new Hex(‘555555’),
new Hex(‘888888’),
new RGB(123,56,77),
new RGB(123,56,77).websafe()
]);
Of course, you also have access to the individual properties of each object, so...
javascript code:
var color = new Hex('004455').toRGB();
// alert (color.r);
// alert (color.g);
// alert (color.b);
// alert (color.toString());
The code itself can be found here:
http://www.madebypi.co.uk/labs/colormatch/colorutils.js
and an example (Firebug is needed) can be found here:
http://www.madebypi.co.uk/labs/colormatch/
ta