L
Lawrence D'Oliveiro
Most graphics APIs seem to want colours specified in RGB space. But RGB is a
poor choice for doing colour manipulations; for example, if you want a
lighter or darker version of a given colour, naive manipulations directly on
the RGB components are likely to lead to hue shifts.
A better space to work in is HSV. This way, you can, say, tweak the
saturation or brightness, and leave the hue unchanged. It is also easier to
predict what colour you are likely to get from a given set of HSV values.
Even if your graphics API doesn’t support it directly, you can still convert
to HSV, do your manipulations there, then convert back to RGB.
Wikipedia has formulas for the conversion. Or you can use code like the HSVA
class here
<https://github.com/ldo/ti5x_android/blob/master/src/GraphicsUseful.java>.
poor choice for doing colour manipulations; for example, if you want a
lighter or darker version of a given colour, naive manipulations directly on
the RGB components are likely to lead to hue shifts.
A better space to work in is HSV. This way, you can, say, tweak the
saturation or brightness, and leave the hue unchanged. It is also easier to
predict what colour you are likely to get from a given set of HSV values.
Even if your graphics API doesn’t support it directly, you can still convert
to HSV, do your manipulations there, then convert back to RGB.
Wikipedia has formulas for the conversion. Or you can use code like the HSVA
class here
<https://github.com/ldo/ti5x_android/blob/master/src/GraphicsUseful.java>.