diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 2c6bc116..2863fea4 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2536,7 +2536,7 @@ uint16_t WS2812FX::mode_glitter() //each needs 12 bytes -//Spark type is used for popcorn and 1D fireworks +//Spark type is used for popcorn, 1D fireworks, and drip typedef struct Spark { float pos; float vel; @@ -2883,3 +2883,76 @@ uint16_t WS2812FX::mode_exploding_fireworks(void) return FRAMETIME; } + + +/* + * Drip Effect + * ported of: https://www.youtube.com/watch?v=sru2fXh4r7k + */ +uint16_t WS2812FX::mode_drip(void) +{ + //allocate segment data + uint16_t numDrops = 2; + uint16_t dataSize = sizeof(spark) * numDrops; + if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed + + fill(SEGCOLOR(1)); + + Spark* drops = reinterpret_cast(SEGENV.data); + + float gravity = -0.001 - (SEGMENT.speed/50000.0); + gravity *= SEGLEN; + int sourcedrop = 12; + + for (int j=0;j255) drops[j].col=255; + setPixelColor(SEGMENT.start + int(drops[j].pos),color_blend(BLACK,SEGCOLOR(0),drops[j].col)); + + drops[j].col += map(SEGMENT.intensity, 0, 255, 1, 6); // swelling + + if (random8() < drops[j].col/10) { // random drop + drops[j].colIndex=2; //fall + drops[j].col=255; + } + } + 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; + drops[j].vel += gravity; + + for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets + setPixelColor(SEGMENT.start + int(drops[j].pos)+i,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling + } + + if (drops[j].colIndex > 2) { // during bounce, some water is on the floor + setPixelColor(SEGMENT.start,color_blend(SEGCOLOR(0),BLACK,drops[j].col)); + } + } else { // we hit bottom + 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/4;// reverse velocity with damping + drops[j].pos += drops[j].vel; + } + drops[j].col = sourcedrop*2; + drops[j].colIndex = 5; // bouncing + } + } + } + } + return FRAMETIME; +} diff --git a/wled00/FX.h b/wled00/FX.h index fdbbfb55..e3a5c3a9 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -91,7 +91,7 @@ #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED ) -#define MODE_COUNT 96 +#define MODE_COUNT 97 #define FX_MODE_STATIC 0 #define FX_MODE_BLINK 1 @@ -189,6 +189,7 @@ #define FX_MODE_SINELON_DUAL 93 #define FX_MODE_SINELON_RAINBOW 94 #define FX_MODE_POPCORN 95 +#define FX_MODE_DRIP 96 class WS2812FX { @@ -365,6 +366,7 @@ class WS2812FX { _mode[FX_MODE_SINELON_DUAL] = &WS2812FX::mode_sinelon_dual; _mode[FX_MODE_SINELON_RAINBOW] = &WS2812FX::mode_sinelon_rainbow; _mode[FX_MODE_POPCORN] = &WS2812FX::mode_popcorn; + _mode[FX_MODE_DRIP] = &WS2812FX::mode_drip; _brightness = DEFAULT_BRIGHTNESS; currentPalette = CRGBPalette16(CRGB::Black); @@ -547,7 +549,8 @@ class WS2812FX { mode_sinelon(void), mode_sinelon_dual(void), mode_sinelon_rainbow(void), - mode_popcorn(void); + mode_popcorn(void), + mode_drip(void); private: @@ -625,7 +628,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([ "Scanner Dual","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","Bpm","Fill Noise", "Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Meteor Smooth","Railway","Ripple", "Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst", -"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn" +"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip" ])=====";