mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-10 06:14:26 +02:00
Created FAQ #6 (markdown)
22
FAQ-#6.md
Normal file
22
FAQ-#6.md
Normal file
@@ -0,0 +1,22 @@
|
||||
### Is there a way to specify a color using a color wheel?
|
||||
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 this 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, as 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);
|
||||
```
|
Reference in New Issue
Block a user