What would be the best way to loop the array and find the best match to
myColor?

A simple way would be do add up the difference to the red, green and
blue values.
You get the value for the channels like this:

var red = color >> 16 & 0xff;
var green = color >> 8 & 0xff;
var blue = color & 0xff;

Then you can do a Math.abs( red1 - red2 ) + Math.abs( green1 - green2
) + Math.abs( blue1 - blue2 ) and you get the total difference between
two colors.

This isn't the most exact way to measure the distance between two
colors as perceived by an average human being, but if you want to
really know that perceived distance, then RGB isn't the right color
space and it gets a bit more complicated:
<http://en.wikipedia.org/wiki/Lab_color_space>

HTH,
Mark



On 10/31/06, Aaron Buchanan <[EMAIL PROTECTED]> wrote:
Hello all!

I am looking for a reference to read up on comparing two or more color
values. I have not done a whole lot of work with color math so any
foundation articles would be great.

What I am trying to accomplish, say I have a var "myColor" which represents
the color I would like to find the closest match for, I also have an array
of other colors that are all shades of yellow:

--

var myColor:Number = 0xffcc00
var similarColors:Array = [ 0xfce427, 0xdcb30a, 0xa48611];

--

What would be the best way to loop the array and find the best match to
myColor?

Thanks in Advance!

--
Aaron Buchanan | Flash Developer, Lab-Media | T 909 702 1368


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to