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. 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)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s