Well, this is not so straightforward, because it depends on how you decide to quantize the color.
You can do this via HSB, which is a more correct way, in my opinion (although this is not necessarily a fact) or just use a hexadecimal value.
this is most quickly possible using hax values
var colour:uint = 0x9900CC; var r:uint = colour >> 16; var g:uint = colour >> 8 & 0xFF; var b:uint = colour & 0xFF;
. This will give you the value of each channel (c) (ABC is the colors)
then do the math for each channel (c)
(cB - cA)/(cC - cA)
then after you get each of these channels, you can add them together and divide by 3.
there is one problem though, if the colors A and C are always the same for any channel, you need to add an exception (because cC and CA are zero and you cannot divide by zero), at this point you also need to decide how to handle that difference.
Daniel
source share