+3  A: 

From what you describe, it sounds like what you really want is a function to find a color's complement, not its inverse. Inverting means something different in this context.

Here's a StackOverflow question regarding complements in JavaScript. Perhaps some of the code is adaptable?

Here is some interesting and potentially useful info about the various ways color can be worked with in Cocoa color spaces. From what it looks like here, if you can use the HSV color space, then the complement of a color could be found by simply taking hue > 179 ? hue -= 180 : hue = += 180, since the hues are defined around the color wheel in a full circle.

phoebus
That Java code looks promising. I'll give it a whirl.
e.James
And thank you for the point about complementary colors vs inverted colors. I'll add that to the question.
e.James
+5  A: 

Simple: The components are all 0–1, so subtract each component from 1 to get the complement's value.

Examples:

  • Red = 1, 0, 0; complement = 0, 1, 1 = cyan
  • Yellow = 1, 1, 0; complement = 0, 0, 1 = blue
  • White = 1, 1, 1; complement = 0, 0, 0 = black
  • Deep orange = 1, 0.25, 0; complement = 0, 0.75, 1 = sky blue

As you can guess, this is a symmetric operation. Inverting the inverse will get you exactly the color you started with.

Peter Hosey
Upvoted for being straightforward about it:)
phoebus