From a004d1647d9e7097c5bb4d55635361a14f79b0c3 Mon Sep 17 00:00:00 2001 From: Def3nder <33399267+Def3nder@users.noreply.github.com> Date: Tue, 11 Feb 2020 22:43:15 +0100 Subject: [PATCH] Simplify Code for Gradient / Loading effect (#671) --- wled00/FX.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 43428fd4..479714fe 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1177,15 +1177,12 @@ uint16_t WS2812FX::mode_fire_flicker(void) { * Gradient run base function */ uint16_t WS2812FX::gradient_base(bool loading) { - uint16_t counter = now * (SEGMENT.speed >> 3) + 1; - SEGENV.step = counter * SEGLEN >> 16; - if (SEGMENT.speed == 0) SEGENV.step = SEGLEN >> 1; - if (SEGENV.call == 0) SEGENV.step = 0; - float per,val; //0.0 = sec 1.0 = pri - float brd = SEGMENT.intensity; - if (!loading) brd = SEGMENT.intensity/2; + uint16_t counter = now * ((SEGMENT.speed >> 2) + 1); + uint16_t pp = counter * SEGLEN >> 16; + if (SEGENV.call == 0) pp = 0; + float val; //0.0 = sec 1.0 = pri + float brd = loading ? SEGMENT.intensity : SEGMENT.intensity/2; if (brd <1.0) brd = 1.0; - int pp = SEGENV.step; int p1 = pp-SEGLEN; int p2 = pp+SEGLEN; @@ -1197,9 +1194,8 @@ uint16_t WS2812FX::gradient_base(bool loading) { } else { val = min(abs(pp-i),min(abs(p1-i),abs(p2-i))); } - per = val/brd; - if (per >1.0) per = 1.0; - setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), per*255)); + val = (brd > val) ? val/brd * 255 : 255; + setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), val)); } return FRAMETIME;