-
-
Notifications
You must be signed in to change notification settings - Fork 264
FAQ #6
The color wheel routines you may have seen in other code is really a hack of the core feature of HSL or HSB(HSV) color space. The number often represented in degrees of 0 to 360 is actually the Hue value for these alternate color spaces. Its called a color wheel as these color spaces are often displayed as a wheel as their target audience was visual designers and not engineers.
NOTE: There is no HsvColor in my library, but HsbColor is really the same thing.
You can thus just use the HslColor or HsbColor objects to accomplish this. In the case of my library, the Hue value range is 0.0 to 1.0 instead of 0 to 360, so some minor math will correct that.
RgbColor WheelColor(uint16_t wheelValue) {
// divide the wheelValue by 360.0f to get a value between 0.0 and 1.0 needed for HslColor
return HslColor(wheelValue / 360.0f, 1.0f, 0.5f); // this will autoconvert back to RgbColor
}
// latter in the code
RgbColor newColor = WheelColor(277);
strip.SetPixelColor(0, newColor);
The better approach is retrain yourself that when you see a wheel value, it means Hue. So you just use either HslColor or HsbColor in the first place.
HslColor newColor(277/360.0f, 1.0f, 0.5f);
strip.SetPixelColor(0, newColor);