# How to rotate colors correctly

I need to "rotate" colors depending on a certain dependency, how do I calculate this?

I'm using no program, just working with a bitmap in C#

For example:

Every pixel, which is `R:193,G:0,B:0` has to become `R:0,G60,B:90`

Now every other color needs to be switched in relation.

`193/0/0` has a neighbor pixel with `205/48/48`, what I'm searching is the relative neighbor pixel of `0/60/90`

Is there a way to calculate this, without getting values above 255 and beneath 0?

• I think the key will be finding the adjustment to hue, saturation, and brightness /value/lightness that turns your dark red into your dark blue, then applying that to everything. How to do this will depend on what software etc is being used. May 15, 2014 at 14:36
• There really is no such thing as color rotation, its just a trick of the color system. You could equally well try HSV as HSL which are subtly different and yield different results. There is no guarantee they yield satisfying results. May 15, 2014 at 14:58

## 1 Answer

This is a complete stab in the dark, but here is what I would try: The HSL values are 200/100/35 and 0/100/76, so rotate the value of each H value by 200° and add 41% to each L value (clipped at 100).

More information from thebodzio's comment:

I think what you really have in mind is “mapping”. In that regard it's like any other mapping between two vector spaces (with some clipping/wrapping; not necessarily bijective process). The problem is, there's infinitely many such mappings. You just have to formulate one that suits you best. @JohnB's proposition seems to be the most reasonable in that regard, however it requires conversion from RGB (sRGB?) to HSL and back. Algorithms are easy enough to find.

• why not rotate -160 degrees which is closer? Jul 14, 2014 at 17:02