TetrixEffect
Source:
TetrixEffect.h
Tetris¶
src/light/effects/TetrixEffect.h:50Per-column falling-brick state, MoonLight's Tetris struct.
Public Attributes¶
float pos = 0.0f
: head position of the falling brick, in LED rows
float speed = 0.0f
: fall speed in rows per frame
uint8_t col = 0
: palette index for this column's bricks
uint16_t brick = 0
: brick height in LEDs
uint16_t stack = 0
: stacked height at the bottom
uint32_t step = 0
: state machine value, or a future millis() timestamp above 2
float roll = 0.0f
: start-roll carry, paced at the reference frame rate
TetrixEffect¶
src/light/effects/TetrixEffect.h:28Inherits:
EffectBase
Tetris-style effect: falling, stacking blocks.
Author: Andrew Tuline (WLED-SR), via the predecessor, https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Nodes/Effects/E_WLED.h

Each column drops a brick of light that falls at its own speed onto a growing stack. Once the stack fills a column, that column blanks to black and the cycle restarts. Every column runs its own state machine, so they desync into a rain of stacking bricks.
Prior art: MoonLight's Tetrix, descended from the WLED effect by Aircoookie and blazoncek.
Public Attributes¶
uint8_t speedControl = 0
: Fall speed, MoonLight's default. 0 gives each brick a random speed.
uint8_t widthControl = 0
: Brick height. 0 randomizes it, otherwise it derives from this.
bool oneColor = false
: Share one slowly-advancing color across a column's bricks.
Public Methods¶
virtual inline const char * tags() const override
: Catalog tags: MoonLight origin, MoonModules.
virtual inline Dim dimensions() const override
: Writes the z=0 slice only, iterating x and y.
virtual inline void defineControls() override
: Publish the fall speed, the brick height and the one-color switch.
virtual inline void prepare() override
: Size one drop per column and give each a 2 s start delay.
virtual inline void tick() override
: Advance every column's state machine and paint its brick and stack.
More info¶
The per-column state machine¶
step carries the state: 0 idle, 1 start-roll, 2 falling. Above 2 it holds a future millis() timestamp instead, for the start delay and the blank delay. The physics come from the MoonLight spec, written fresh on EffectBase and the draw primitives. With oneColor a column's bricks share one slowly-advancing palette index, else each is random.