Can you check how similar a code is to another colour, If e.g. 0xFFFFFF is similar to 0xFBFBFB then change colour.
im not sure how the colour code works, so if you know a tip on the code, can you please share
Can you check how similar a code is to another colour, If e.g. 0xFFFFFF is similar to 0xFBFBFB then change colour.
im not sure how the colour code works, so if you know a tip on the code, can you please share
A simple method to determinate proximity between colors, is to do so for each color component. In AS3, a color is a number containing 3 components : red, green and blue (There's sometimes a fourth component for transparency - alpha)
Each component is contained in 1 byte, for a value of 0 to 255. (0x00 to 0xFF) Here is a way to get each color component from the color itself :
var red:int = (color & 0xFF0000) >>> 16;
var green:int = (color & 0xFF00) >>> 8;
var blue:int = color & 0xFF;
Once you have the color components of each color, you can compare them 2 by 2, and combine the results:
var red_proximity = Math.abs(red1 - red2);
var green_proximity = Math.abs(green1 - green2);
var blue_proximity = Math.abs(blue1 - blue2);
var color_proximity = red_proximity + green_proximity + blue_proximity;
The result will be a number between 0 and 765; 0 meaning the color are exactly the same, and 765 meaning that they are completely differents. (Note that I am using Math.abs() to ensure that the proximity values are always positive.)
The last step now is to choose a threshold value to determine if the colors are "too close". The chosen value is usually arbitrary, so test a few and take your pick. For the example, I'm using the value '84'.
if (color_proximity < 84) {
// color is too close : change it
} else {
// color is okay : do nothing ?
}
This is only one method, and if you have to play a lot with colors, search a bit on the web for other algorithm; It's always usefull.