Skip to content

Commit f7114fc

Browse files
authored
Merge pull request wled#1729 from blazoncek/tetris-fx
Tetris (falling bricks) effect & Colortwinkles low brightness fix.
2 parents 8e71c3a + 7092f33 commit f7114fc

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

wled00/FX.cpp

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,6 @@ uint16_t WS2812FX::mode_running_color(void) {
10011001
return running(SEGCOLOR(0), SEGCOLOR(1));
10021002
}
10031003

1004-
1005-
/*
1006-
* Alternating red/green pixels running.
1007-
*/
1008-
uint16_t WS2812FX::mode_merry_christmas(void) {
1009-
return running(RED, GREEN);
1010-
}
1011-
10121004
/*
10131005
* Alternating red/white pixels running.
10141006
*/
@@ -1991,7 +1983,7 @@ uint16_t WS2812FX::mode_colortwinkle()
19911983
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
19921984

19931985
CRGB fastled_col, prev;
1994-
fract8 fadeUpAmount = 8 + (SEGMENT.speed/4), fadeDownAmount = 5 + (SEGMENT.speed/7);
1986+
fract8 fadeUpAmount = _brightness>28 ? 8 + (SEGMENT.speed>>2) : 68-_brightness, fadeDownAmount = _brightness>28 ? 8 + (SEGMENT.speed>>3) : 68-_brightness;
19951987
for (uint16_t i = 0; i < SEGLEN; i++) {
19961988
fastled_col = col_to_crgb(getPixelColor(i));
19971989
prev = fastled_col;
@@ -3144,6 +3136,59 @@ uint16_t WS2812FX::mode_drip(void)
31443136
}
31453137

31463138

3139+
/*
3140+
* Tetris or Stacking (falling bricks) Effect
3141+
* by Blaz Kristan (https://github.com/blazoncek, https://blaz.at/home)
3142+
*/
3143+
typedef struct Tetris {
3144+
float pos;
3145+
float speed;
3146+
uint32_t col;
3147+
} tetris;
3148+
3149+
uint16_t WS2812FX::mode_tetrix(void) {
3150+
3151+
uint16_t dataSize = sizeof(tetris);
3152+
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
3153+
Tetris* drop = reinterpret_cast<Tetris*>(SEGENV.data);
3154+
3155+
// initialize dropping on first call or segment full
3156+
if (SEGENV.call == 0 || SEGENV.aux1 >= SEGLEN) {
3157+
SEGENV.aux1 = 0; // reset brick stack size
3158+
SEGENV.step = 0;
3159+
fill(SEGCOLOR(1));
3160+
return 250; // short wait
3161+
}
3162+
3163+
if (SEGENV.step == 0) { //init
3164+
drop->speed = 0.0238 * (SEGMENT.speed ? (SEGMENT.speed>>3)+1 : random8(6,40)); // set speed
3165+
drop->pos = SEGLEN-1; // start at end of segment
3166+
drop->col = color_from_palette(random8(0,15)<<4,false,false,0); // limit color choices so there is enough HUE gap
3167+
SEGENV.step = 1; // drop state (0 init, 1 forming, 2 falling)
3168+
SEGENV.aux0 = (SEGMENT.intensity ? (SEGMENT.intensity>>5)+1 : random8(1,5)) * (1+(SEGLEN>>6)); // size of brick
3169+
}
3170+
3171+
if (SEGENV.step == 1) { // forming
3172+
if (random8()>>6) { // random drop
3173+
SEGENV.step = 2; // fall
3174+
}
3175+
}
3176+
3177+
if (SEGENV.step > 1) { // falling
3178+
if (drop->pos > SEGENV.aux1) { // fall until top of stack
3179+
drop->pos -= drop->speed; // may add gravity as: speed += gravity
3180+
if (int(drop->pos) < SEGENV.aux1) drop->pos = SEGENV.aux1;
3181+
for (uint16_t i=int(drop->pos); i<SEGLEN; i++) setPixelColor(i,i<int(drop->pos)+SEGENV.aux0 ? drop->col : SEGCOLOR(1));
3182+
} else { // we hit bottom
3183+
SEGENV.step = 0; // go back to init
3184+
SEGENV.aux1 += SEGENV.aux0; // increase the stack size
3185+
if (SEGENV.aux1 >= SEGLEN) return 1000; // wait for a second
3186+
}
3187+
}
3188+
return FRAMETIME;
3189+
}
3190+
3191+
31473192
/*
31483193
/ Plasma Effect
31493194
/ adapted from https://github.com/atuline/FastLED-Demos/blob/master/plasma/plasma.ino

wled00/FX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
#define FX_MODE_COMET 41
165165
#define FX_MODE_FIREWORKS 42
166166
#define FX_MODE_RAIN 43
167-
#define FX_MODE_MERRY_CHRISTMAS 44
167+
#define FX_MODE_TETRIX 44
168168
#define FX_MODE_FIRE_FLICKER 45
169169
#define FX_MODE_GRADIENT 46
170170
#define FX_MODE_LOADING 47
@@ -501,7 +501,7 @@ class WS2812FX {
501501
_mode[FX_MODE_COMET] = &WS2812FX::mode_comet;
502502
_mode[FX_MODE_FIREWORKS] = &WS2812FX::mode_fireworks;
503503
_mode[FX_MODE_RAIN] = &WS2812FX::mode_rain;
504-
_mode[FX_MODE_MERRY_CHRISTMAS] = &WS2812FX::mode_merry_christmas;
504+
_mode[FX_MODE_TETRIX] = &WS2812FX::mode_tetrix;
505505
_mode[FX_MODE_FIRE_FLICKER] = &WS2812FX::mode_fire_flicker;
506506
_mode[FX_MODE_GRADIENT] = &WS2812FX::mode_gradient;
507507
_mode[FX_MODE_LOADING] = &WS2812FX::mode_loading;
@@ -717,7 +717,7 @@ class WS2812FX {
717717
mode_comet(void),
718718
mode_fireworks(void),
719719
mode_rain(void),
720-
mode_merry_christmas(void),
720+
mode_tetrix(void),
721721
mode_halloween(void),
722722
mode_fire_flicker(void),
723723
mode_gradient(void),
@@ -884,7 +884,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
884884
"Scan","Scan Dual","Fade","Theater","Theater Rainbow","Running","Saw","Twinkle","Dissolve","Dissolve Rnd",
885885
"Sparkle","Sparkle Dark","Sparkle+","Strobe","Strobe Rainbow","Strobe Mega","Blink Rainbow","Android","Chase","Chase Random",
886886
"Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Running 2","Aurora","Stream",
887-
"Scanner","Lighthouse","Fireworks","Rain","Merry Christmas","Fire Flicker","Gradient","Loading","Police","Police All",
887+
"Scanner","Lighthouse","Fireworks","Rain","Tetrix","Fire Flicker","Gradient","Loading","Police","Police All",
888888
"Two Dots","Two Areas","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet",
889889
"Scanner Dual","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","Bpm","Fill Noise",
890890
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Meteor Smooth","Railway","Ripple",

0 commit comments

Comments
 (0)