Skip to content

Commit

Permalink
Make color_wheel rotate in HSV sapce instead of linearly interpolatin…
Browse files Browse the repository at this point in the history
…g R->G->B
  • Loading branch information
TripleWhy committed Jan 13, 2024
1 parent 874b24f commit 760a1d4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,20 +1022,23 @@ void Segment::blur(uint8_t blur_amount) {
/*
* Put a value 0 to 255 in to get a color value.
* The colours are a transition r -> g -> b -> back to r
* Inspired by the Adafruit examples.
* Rotates the color in HSV space, where pos is H. (0=0deg, 256=360deg)
*/
uint32_t Segment::color_wheel(uint8_t pos) {
if (palette) return color_from_palette(pos, false, true, 0);
uint8_t w = W(currentColor(0));
pos = 255 - pos;
if (pos < 85) {
return RGBW32((255 - pos * 3), 0, (pos * 3), w);
} else if(pos < 170) {
pos -= 85;
return RGBW32(0, (pos * 3), (255 - pos * 3), w);
} else {
pos -= 170;
return RGBW32((pos * 3), (255 - pos * 3), 0, w);
// These h and f values are the same h and f you have in the regular HSV to RGB conversion.
// The whole funciton really is just a HSV conversion, but assuming H=pos, S=1 and V=1.
const uint32_t h = (pos * 3) / 128;
const uint32_t f = (pos * 6) % 256;
switch (h) {
case 0: return RGBW32(255 , f , 0 , w);
case 1: return RGBW32(255 - f, 255 , 0 , w);
case 2: return RGBW32(0 , 255 , f , w);
case 3: return RGBW32(0 , 255 - f, 255 , w);
case 4: return RGBW32(f , 0 , 255 , w);
case 5: return RGBW32(255 , 0 , 255 - f, w);
default: return 0;
}
}

Expand Down

0 comments on commit 760a1d4

Please sign in to comment.