@@ -1991,7 +1991,7 @@ uint16_t WS2812FX::mode_colortwinkle()
19911991 if (!SEGENV.allocateData (dataSize)) return mode_static (); // allocation failed
19921992
19931993 CRGB fastled_col, prev;
1994- fract8 fadeUpAmount = 8 + (SEGMENT.speed / 4 ) , fadeDownAmount = 5 + (SEGMENT.speed / 7 ) ;
1994+ fract8 fadeUpAmount = _brightness> 28 ? 8 + (SEGMENT.speed >> 2 ) : 68 -_brightness , fadeDownAmount = _brightness> 28 ? 8 + (SEGMENT.speed >> 3 ) : 68 -_brightness ;
19951995 for (uint16_t i = 0 ; i < SEGLEN; i++) {
19961996 fastled_col = col_to_crgb (getPixelColor (i));
19971997 prev = fastled_col;
@@ -3144,6 +3144,59 @@ uint16_t WS2812FX::mode_drip(void)
31443144}
31453145
31463146
3147+ /*
3148+ * Tetris or Stacking (falling bricks) Effect
3149+ * by Blaz Kristan (https://github.com/blazoncek, https://blaz.at/home)
3150+ */
3151+ typedef struct Tetris {
3152+ float pos;
3153+ float speed;
3154+ uint32_t col;
3155+ } tetris;
3156+
3157+ uint16_t WS2812FX::mode_tetris (void ) {
3158+
3159+ uint16_t dataSize = sizeof (tetris);
3160+ if (!SEGENV.allocateData (dataSize)) return mode_static (); // allocation failed
3161+ Tetris* drop = reinterpret_cast <Tetris*>(SEGENV.data );
3162+
3163+ // initialize dropping on first call or segment full
3164+ if (SEGENV.call == 0 || SEGENV.aux1 >= SEGLEN) {
3165+ SEGENV.aux1 = 0 ; // reset brick stack size
3166+ SEGENV.step = 0 ;
3167+ fill (SEGCOLOR (1 ));
3168+ return 250 ; // short wait
3169+ }
3170+
3171+ if (SEGENV.step == 0 ) { // init
3172+ drop->speed = 0.0238 * (SEGMENT.speed ? (SEGMENT.speed >>4 )+1 : random8 (3 ,20 )); // set speed
3173+ drop->pos = SEGLEN-1 ; // start at end of segment
3174+ drop->col = color_from_palette (random8 (0 ,15 )<<4 ,false ,false ,0 ); // limit color choices so there is enough HUE gap
3175+ SEGENV.step = 1 ; // drop state (0 init, 1 forming, 2 falling)
3176+ SEGENV.aux0 = (SEGMENT.intensity ? (SEGMENT.intensity >>5 )+1 : random8 (1 ,5 )) * (1 +(SEGLEN>>6 )); // size of brick
3177+ }
3178+
3179+ if (SEGENV.step == 1 ) { // forming
3180+ if (random8 ()>>6 ) { // random drop
3181+ SEGENV.step = 2 ; // fall
3182+ }
3183+ }
3184+
3185+ if (SEGENV.step > 1 ) { // falling
3186+ if (drop->pos > SEGENV.aux1 ) { // fall until top of stack
3187+ drop->pos -= drop->speed ; // may add gravity as: speed += gravity
3188+ if (int (drop->pos ) < SEGENV.aux1 ) drop->pos = SEGENV.aux1 ;
3189+ for (uint16_t i=int (drop->pos ); i<SEGLEN; i++) setPixelColor (i,i<int (drop->pos )+SEGENV.aux0 ? drop->col : SEGCOLOR (1 ));
3190+ } else { // we hit bottom
3191+ SEGENV.step = 0 ; // go back to init
3192+ SEGENV.aux1 += SEGENV.aux0 ; // increase the stack size
3193+ if (SEGENV.aux1 >= SEGLEN) return 1000 ; // wait for a second
3194+ }
3195+ }
3196+ return FRAMETIME;
3197+ }
3198+
3199+
31473200/*
31483201/ Plasma Effect
31493202/ adapted from https://github.com/atuline/FastLED-Demos/blob/master/plasma/plasma.ino
0 commit comments