Does anybody know, off the top of your heads, a Javascript solution for calculating the complementary colour of a hex value?
There is a number of colour picking suites and palette generators on the web but I haven't seen any that calculate the colour live using JS.
A detailed hint or a snippet would be very much appreciated.
None of the other functions here worked out the box, so I made this one.
It takes a hex value, converts it to HSL, shifts the hue 180 degrees and converts back to Hex
Parsed through http://design.geckotribe.com/colorwheel/
I find that taking the bit-wise complement works well, and quickly.
I'm not sure if it's a perfect complement in the sense of "mixes together to form a 70% grey", however a 70% grey is "pure white" in terms of color timing in film. It occurred to me that XORing the RGB hex out of pure white might be a good first approximation. You could also try a darker grey to see how that works for you.
Again, this is a fast approximation and I make no guarantees that it'll be perfectly accurate.
See https://github.com/alfl/textful/blob/master/app.js#L38 for my implementation.
Rather than reinventing the wheel, I found a library to work with colors.
Tiny Color
This is how you would implement some of the other answers using it.