How do I invert a colour?

It depends on what do you mean by “inverting” a color

Your code provides a “negative” color.

Are you looking for transform red in cyan, green in purple, blue in yellow (and so on) ? If so, you need to convert your RGB color in HSV mode (you will find here to make the transformation).

Then you just need to invert the Hue value (change Hue by 360-Hue) and convert back to RGB mode.

EDIT: as Alex Semeniuk has mentioned, changing Hue by (Hue + 180) % 360 is a better solution (it does not invert the Hue, but find the opposite color on the color circle)

Leave a Comment