From 0db513f0ee4c92f5993916ac58a2b03a93bdf477 Mon Sep 17 00:00:00 2001 From: Ewowi Date: Sun, 11 Sep 2022 12:35:26 +0200 Subject: [PATCH] Redo improved mode_drip - add palettes - add fall rate slider - increased gravity range - => range varies from 'guess where the next drop falls' to 'raining cats and dogs' --- wled00/FX.cpp | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index b0459cee..27524015 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3367,12 +3367,6 @@ uint16_t mode_exploding_fireworks(void) static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gravity,Firing side;!,!,;!=11;ix=128,1d,2d"; -// float version of map() -static float mapf(float x, float in_min, float in_max, float out_min, float out_max){ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - - /* * Drip Effect * ported of: https://www.youtube.com/watch?v=sru2fXh4r7k @@ -3391,34 +3385,35 @@ uint16_t mode_drip(void) struct virtualStrip { static void runStrip(uint16_t stripNr, Spark* drops) { - uint8_t numDrops = map(SEGMENT.intensity, 0, 255, 1, 4); + uint8_t numDrops = 1 + (SEGMENT.intensity >> 6); // 255>>6 = 3 - float gravity = -0.0005 - (SEGMENT.speed/25000.0); //increased max speed 50000->25000 + float gravity = -0.0005 - (SEGMENT.speed/25000.0); //increased gravity (50000 to 25000) gravity *= SEGLEN-1; - // const int sourcedrop = 12; + int sourcedrop = 12; for (int j=0;j0 && drops[j-1].colIndex > 1 && drops[j].colIndex == 0) drops[j].colIndex = 1; + uint32_t dropColor = drops[j].velX; - if (drops[j].colIndex==1) { // forming - if (drops[j].col>255) { // swelling/brightness max, start falling + SEGMENT.setPixelColor(indexToVStrip(SEGLEN-1, stripNr), color_blend(BLACK,dropColor, sourcedrop));// water source + if (drops[j].colIndex==1) { + if (drops[j].col>255) drops[j].col=255; + SEGMENT.setPixelColor(indexToVStrip(uint16_t(drops[j].pos), stripNr), color_blend(BLACK,dropColor,drops[j].col)); + + drops[j].col += map(SEGMENT.custom1, 0, 255, 1, 6); // swelling + + if (random16() <= drops[j].col * SEGMENT.custom1 * SEGMENT.custom1 / 10 / 128) { // random drop + drops[j].colIndex=2; //fall drops[j].col=255; - drops[j].colIndex=2; // fall } - //draw forming drop (lower the brightness so forming is more visible) - SEGMENT.setPixelColor(indexToVStrip(uint16_t(drops[j].pos), stripNr), color_blend(BLACK, drops[j].velX, drops[j].col/8)); - - drops[j].col += mapf(SEGMENT.custom1, 0, 255, 0.01, 2.5) * random8()/128; // swelling with randomness } - else if (drops[j].colIndex > 1) { // falling + if (drops[j].colIndex > 1) { // falling if (drops[j].pos > 0) { // fall until end of segment drops[j].pos += drops[j].vel; if (drops[j].pos < 0) drops[j].pos = 0; @@ -3426,22 +3421,24 @@ uint16_t mode_drip(void) for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets uint16_t pos = constrain(uint16_t(drops[j].pos) +i, 0, SEGLEN-1); //this is BAD, returns a pos >= SEGLEN occasionally - SEGMENT.setPixelColor(indexToVStrip(pos, stripNr), color_blend(BLACK, drops[j].velX, drops[j].col/i)); //spread pixel with fade while falling + SEGMENT.setPixelColor(indexToVStrip(pos, stripNr), color_blend(BLACK,dropColor,drops[j].col/i)); //spread pixel with fade while falling } if (drops[j].colIndex > 2) { // during bounce, some water is on the floor - SEGMENT.setPixelColor(indexToVStrip(0, stripNr), color_blend(drops[j].velX, BLACK, drops[j].col)); + SEGMENT.setPixelColor(indexToVStrip(0, stripNr), color_blend(dropColor,BLACK,drops[j].col)); } } else { // we hit bottom - if (drops[j].colIndex == 5) { // already hit once, so back to forming + if (drops[j].colIndex > 2) { // already hit once, so back to forming drops[j].colIndex = 0; + // drops[j].col = sourcedrop; + } else { if (drops[j].colIndex==2) { // init bounce - drops[j].vel = -drops[j].vel/3;// reverse velocity with damping + drops[j].vel = -drops[j].vel/4;// reverse velocity with damping drops[j].pos += drops[j].vel; } - drops[j].col = 24; // low brightness + drops[j].col = sourcedrop*2; drops[j].colIndex = 5; // bouncing } } @@ -3455,7 +3452,7 @@ uint16_t mode_drip(void) return FRAMETIME; } -static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips,Swelling;!,!;!;mp12=1,1d"; //bar +static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips,Fall ratio;!,!;!;mp12=1,1d"; //bar /* @@ -6146,6 +6143,11 @@ static const char _data_FX_MODE_2DWAVERLY[] PROGMEM = "Waverly@Amplification,Sen #endif // WLED_DISABLE_2D +// float version of map() +static float mapf(float x, float in_min, float in_max, float out_min, float out_max){ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + // Gravity struct requited for GRAV* effects typedef struct Gravity { int topLED;