Calculate color...

Comanche
01-21-2005, 03:29 AM
I had this question years ago, but then it was just a matter of curiousity, and now it became important:

Suppose I got RGB-color "A". How can I calculate color "B" which will "differ" from given "A" - so that when placed close to each other (in some GUI) they can't be "mixed" by our eyes?

I think this can be really done mathematically, but I don't know how.
Besides - as I may suppose - too many values can be calculated for color "B", so possibly it's a good idea to add one more condition to this task: «Color "B" should be a gradation of a second given color "C"». E.g. it can be made through fixing one of the (R, G, B) values of the desired color...

Any ideas?

jeroenreimert
01-21-2005, 04:20 AM
Detecting an clear difference between 2 colors doesn't need a lot of math
Just imagine the different colors as separate dimensions, all the colors laid out in this 3d space will form a Cube. The distance(try to see it a vector) between 2 colors in the cube should define the difference in color. The distance between colors can easily be calculated by using Pythagoras.

Calculating a 2nd color will be little harder, and only 1 extra argument won't be sufficient. A Vector has 2 variables: Length(we know) and angle(we have to calculate). you've got to know in what direction the 2nd is(maybe opposing corner of the cube?)

Good luck!

eXeption
01-21-2005, 04:45 AM
For general use you can compliment the color to obtain a contrast. How ever when the color becomes more grey (ie shades with very low saturation) dont exhibit much difference, you can avoid this by performing another operation...
thus here is an informal algorithm

Check if the source color has enough saturation... (use any RGB to HSV algorithm)
If it has output the compliment of the source color
Otherwise perform another operation (such as XORing with &HC0C0C0 etc..)

'
HK

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum