BouncingBallsEffect
Source:
BouncingBallsEffect.h
Ball¶
src/light/effects/BouncingBallsEffect.h:117One ball's persistent state, height being recomputed analytically each frame.
Public Attributes¶
float impactVelocity = 0.0f
: its speed leaving the last bounce
uint32_t lastBounceTime = 0
: when that bounce happened, which starts its clock
BouncingBallsEffect¶
src/light/effects/BouncingBallsEffect.h:27Inherits:
EffectBase
Physics effect: gravity-bounced balls trailing along the layer.
Author: Andrew Tuline (WLED-SR), via the predecessor, https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Nodes/Effects/E_WLED.h
One column of balls per x, each launched upward and bouncing with energy loss. A ball is relaunched once its velocity dies out. Every column runs independently, so a panel shows a forest of bouncing dots.
Prior art: MoonLight's BouncingBalls, generalizing WLED's own from the FastLED demo lineage.
Public Attributes¶
uint8_t grav = 128
: Gravity's strength, where higher falls faster.
uint8_t numBalls = 8
: How many balls each column carries.
Public Methods¶
virtual inline const char * tags() const override
: Catalog tags: MoonLight origin, WLED lineage.
virtual inline Dim dimensions() const override
: Writes the z=0 slice, one ball column per x, which extrude duplicates through a volume.
virtual inline void defineControls() override
: Publish gravity and the ball count.
virtual inline void prepare() override
: Size one ball array per column, flattened, which zero-fills into a first-frame bounce.
virtual inline void tick() override
: Advance every ball on its own clock, bouncing and relaunching, and draw each one.
Public Static Attributes¶
constexpr uint8_t maxNumBalls = 16
: The per-column ceiling, and the stride of the flattened ball array.
More info¶
The motion is analytic, not integrated¶
A ball's height is the projectile equation evaluated against its own clock. So the trajectory is real physics rather than a frame-step integration that drifts. Only impactVelocity and lastBounceTime carry between frames, and height is recomputed.
Reproduced from the source: its gravity, time scale, dampening, kick and palette spacing.