diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 540a1ad3..b0459cee 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3367,6 +3367,12 @@ 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 @@ -3385,33 +3391,34 @@ uint16_t mode_drip(void) struct virtualStrip { static void runStrip(uint16_t stripNr, Spark* drops) { - uint8_t numDrops = 1 + (SEGMENT.intensity >> 6); // 255>>6 = 3 + uint8_t numDrops = map(SEGMENT.intensity, 0, 255, 1, 4); - float gravity = -0.0005 - (SEGMENT.speed/50000.0); + float gravity = -0.0005 - (SEGMENT.speed/25000.0); //increased max speed 50000->25000 gravity *= SEGLEN-1; - int sourcedrop = 12; + // const int sourcedrop = 12; for (int j=0;j0 && drops[j-1].colIndex > 1 && drops[j].colIndex == 0) drops[j].colIndex = 1; - SEGMENT.setPixelColor(indexToVStrip(SEGLEN-1, stripNr), color_blend(BLACK,SEGCOLOR(0), 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,SEGCOLOR(0),drops[j].col)); - - drops[j].col += map(SEGMENT.speed, 0, 255, 1, 6); // swelling - - if (random8() < drops[j].col/10) { // random drop - drops[j].colIndex=2; //fall + if (drops[j].colIndex==1) { // forming + if (drops[j].col>255) { // swelling/brightness max, start falling 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 } - if (drops[j].colIndex > 1) { // falling + else 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; @@ -3419,24 +3426,22 @@ 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,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling + SEGMENT.setPixelColor(indexToVStrip(pos, stripNr), color_blend(BLACK, drops[j].velX, 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(SEGCOLOR(0),BLACK,drops[j].col)); + SEGMENT.setPixelColor(indexToVStrip(0, stripNr), color_blend(drops[j].velX, BLACK, drops[j].col)); } } else { // we hit bottom - if (drops[j].colIndex > 2) { // already hit once, so back to forming + if (drops[j].colIndex == 5) { // 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/4;// reverse velocity with damping + drops[j].vel = -drops[j].vel/3;// reverse velocity with damping drops[j].pos += drops[j].vel; } - drops[j].col = sourcedrop*2; + drops[j].col = 24; // low brightness drops[j].colIndex = 5; // bouncing } } @@ -3450,7 +3455,7 @@ uint16_t mode_drip(void) return FRAMETIME; } -static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips;!,!;!;mp12=1,1d"; //bar +static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips,Swelling;!,!;!;mp12=1,1d"; //bar /* @@ -6141,11 +6146,6 @@ 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;