Skip to content

Commit b8b59b2

Browse files
authored
Make rainbow effects more colorful (#3681)
* Make color_wheel rotate in HSV sapce instead of linearly interpolating R->G->B * Remove the rainbow wheel option, as that is the same as the rainbow palette * Use hsv2rgb for color_wheel This is the current result of the discussion in #3681
1 parent c8d8ab0 commit b8b59b2

File tree

6 files changed

+5
-24
lines changed

6 files changed

+5
-24
lines changed

wled00/FX_fcn.cpp

100755100644
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,27 +1085,14 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
10851085
/*
10861086
* Put a value 0 to 255 in to get a color value.
10871087
* The colours are a transition r -> g -> b -> back to r
1088-
* Inspired by the Adafruit examples.
1088+
* Rotates the color in HSV space, where pos is H. (0=0deg, 256=360deg)
10891089
*/
10901090
uint32_t Segment::color_wheel(uint8_t pos) const {
1091-
if (palette) return color_from_palette(pos, false, false, 0); // never wrap palette
1091+
if (palette) return color_from_palette(pos, false, false, 0); // only wrap if "always wrap" is set
10921092
uint8_t w = W(getCurrentColor(0));
1093-
pos = 255 - pos;
1094-
if (useRainbowWheel) {
1095-
CRGB rgb;
1096-
hsv2rgb_rainbow(CHSV(pos, 255, 255), rgb);
1097-
return RGBW32(rgb.r, rgb.g, rgb.b, w);
1098-
} else {
1099-
if (pos < 85) {
1100-
return RGBW32((255 - pos * 3), 0, (pos * 3), w);
1101-
} else if (pos < 170) {
1102-
pos -= 85;
1103-
return RGBW32(0, (pos * 3), (255 - pos * 3), w);
1104-
} else {
1105-
pos -= 170;
1106-
return RGBW32((pos * 3), (255 - pos * 3), 0, w);
1107-
}
1108-
}
1093+
uint32_t rgb;
1094+
hsv2rgb(CHSV32(static_cast<uint16_t>(pos << 8), 255, 255), rgb);
1095+
return rgb | (w << 24); // add white channel
11091096
}
11101097

11111098
/*

wled00/cfg.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
519519
CJSON(briMultiplier, light[F("scale-bri")]);
520520
CJSON(paletteBlend, light[F("pal-mode")]);
521521
CJSON(strip.autoSegments, light[F("aseg")]);
522-
CJSON(useRainbowWheel, light[F("rw")]);
523522

524523
CJSON(gammaCorrectVal, light["gc"]["val"]); // default 2.2
525524
float light_gc_bri = light["gc"]["bri"];
@@ -1042,7 +1041,6 @@ void serializeConfig(JsonObject root) {
10421041
light[F("scale-bri")] = briMultiplier;
10431042
light[F("pal-mode")] = paletteBlend;
10441043
light[F("aseg")] = strip.autoSegments;
1045-
light[F("rw")] = useRainbowWheel;
10461044

10471045
JsonObject light_gc = light.createNestedObject("gc");
10481046
light_gc["bri"] = (gammaCorrectBri) ? gammaCorrectVal : 1.0f; // keep compatibility

wled00/data/settings_leds.htm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,6 @@ <h3>Advanced</h3>
908908
<option value="3">None (not recommended)</option>
909909
</select><br>
910910
Use harmonic <i>Random Cycle</i> palette: <input type="checkbox" name="TH"><br>
911-
Use &quot;rainbow&quot; color wheel: <input type="checkbox" name="RW"><br>
912911
Target refresh rate: <input type="number" class="s" min="0" max="250" name="FR" oninput="UI()" required> FPS
913912
<div id="fpsNone" class="warn" style="display: none;">&#9888; Unlimited FPS Mode is experimental &#9888;<br></div>
914913
<div id="fpsHigh" class="warn" style="display: none;">&#9888; High FPS Mode is experimental.<br></div>

wled00/set.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
351351
t = request->arg(F("TP")).toInt();
352352
randomPaletteChangeTime = MIN(255,MAX(1,t));
353353
useHarmonicRandomPalette = request->hasArg(F("TH"));
354-
useRainbowWheel = request->hasArg(F("RW"));
355354

356355
nightlightTargetBri = request->arg(F("TB")).toInt();
357356
t = request->arg(F("TL")).toInt();

wled00/wled.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ WLED_GLOBAL unsigned long transitionStartTime;
625625
WLED_GLOBAL bool jsonTransitionOnce _INIT(false); // flag to override transitionDelay (playlist, JSON API: "live" & "seg":{"i"} & "tt")
626626
WLED_GLOBAL uint8_t randomPaletteChangeTime _INIT(5); // amount of time [s] between random palette changes (min: 1s, max: 255s)
627627
WLED_GLOBAL bool useHarmonicRandomPalette _INIT(true); // use *harmonic* random palette generation (nicer looking) or truly random
628-
WLED_GLOBAL bool useRainbowWheel _INIT(false); // use "rainbow" color wheel instead of "spectrum" color wheel
629628

630629
// nightlight
631630
WLED_GLOBAL bool nightlightActive _INIT(false);

wled00/xml.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ void getSettingsJS(byte subPage, Print& settingsScript)
382382
printSetFormValue(settingsScript,PSTR("TL"),nightlightDelayMinsDefault);
383383
printSetFormValue(settingsScript,PSTR("TW"),nightlightMode);
384384
printSetFormIndex(settingsScript,PSTR("PB"),paletteBlend);
385-
printSetFormCheckbox(settingsScript,PSTR("RW"),useRainbowWheel);
386385
printSetFormValue(settingsScript,PSTR("RL"),rlyPin);
387386
printSetFormCheckbox(settingsScript,PSTR("RM"),rlyMde);
388387
printSetFormCheckbox(settingsScript,PSTR("RO"),rlyOpenDrain);

0 commit comments

Comments
 (0)