Search code examples
actionscript-3path-finding

Finding close colors of a given color


I´d like to know, how, through actionscript 3, to get an array of ARGB (hexadecimal) colors, that is close to a given color.

Example:

0xFF00FF00

A green.

How to get variations of green?

I´m trying to get some green colors of a bitmapdata. I´ve tried to get it by making a loop getting the colors using getPixels32. The problem is, I think the bits colors of each position are different from the bits of the bitmap rendered.

It´s for a pathfinder. Each green bit sets a node in a map, as walkable. So I need to know what are these colors to set it as walkable for the pathfinder.

Any suggestions?


Solution

  • RGB space is terrible for interpreting whether colors are similar to one another. A different color space that matches closer to human perception of color is HSV (hue saturation and value). Here are the steps you should follow:

    1. Convert your value from RGB space to HSV (http://www.cs.rit.edu/~ncs/color/t_convert.html)
    2. Modify the saturation and value to obtain different shades of the same green hue.
    3. You can even modify the hue a little with a defined tolerance level you specify
    4. Reconvert back to HSV to RGB

    I believe technically..one color space is smaller than the other, meaning it is not always a 1:1 conversion - but it should serve your purpose.