geeky

# inverse color

while working on my new store script, i learned about inverse color. The inverse of a color is the most contrasting color of that color.

[geektalk] Mathematically, it’s the complement of current RGB value of the color. On the web, each color is represented in either a HEXCODE or its RGB (red, green, blue) form. The hexcode is a representation of the color’s RGB value. Hex means base 16. It’s consisted of 1-9 Plus A-F. Since two hex code can represent up to 256 decimals because 162 = 256 (representing 0 – 255), the first two digit of the hexcode is the color’s red value. The second is the green value and third is the blue value. So after we convert the hexcode representation of the color to its respective red, green and blue values and substract each from 255. Then convert them back to hex and concatenate them. We get its complement color or inverse.[/geektalk]

Either way, if you don’t know what I’m talking about, just take a look at this example. You will get it.

in my scripts collection, i also give you a php function which is 10 times easier to write than the javascript version of it.

## 5 thoughts on “inverse color”

1. very cool… what kind of store script are you working on?

1. a very fancy one. unfortunately non dmb members will not be able to see 😦

2. Hmmm… I couldn’t get the inverse script to work… will try again…

3. Mark says:

This is the approach I took in a recent application, unfortunatly this doesnt work for 808080 or other colours with all three RGB values close to the central figure of 128 as it produces a colour whcih is too similar: IE

808080 = 128, 128, 128 = (255-128), (255-128), (255-128) = 127, 127, 127 = grey on grey = illegible(just try 808080 in your script)