Skip to content

VectorBallsEffect

Source: VectorBallsEffect.h

VectorBallsEffect

class VectorBallsEffect
src/light/effects/VectorBallsEffect.h:33

Inherits: EffectBase

Effect: a rotating 3D object of shaded spheres, drawn with real perspective.

VectorBallsEffect card VectorBallsEffect controls

The smallest complete demonstration of putting 3D on a panel. Every step is a shared power function rather than something this effect invented.

Prior art: the demoscene vector-ball effect, where the projection and shading are the library's.

Public Attributes

uint8_t bpm = 12 : Rotation speed.

uint8_t size = 2 : A ball's radius at the object's center, in pixels.

uint8_t spread = 90 : How far apart the balls sit.

uint8_t distance = 200 : How far the object is from the viewer.

bool fade = true : Dim the far balls, which is what reads as depth.

Public Methods

virtual inline const char * tags() const override : Catalog tags: this effect is the power-function showcase.

virtual inline Dim dimensions() const override : Writes the z=0 slice, which extrude fills through a volume.

virtual inline void defineControls() override : Publish the rotation, the object's shape and the camera.

virtual inline void tick() override : Rotate and project every point, sort them back to front, then draw each as a disc.

More info

Five steps, all of them shared

Two [shader::rotate] calls turn the object, one per axis. [shader::project] puts it on screen, which is the one divide that is perspective. A painter's-order pass sorts back to front and [shader::depthFade] shades by distance. [draw::fillCircle] then draws each ball at the size that same divide gives it.

Painter's order matters: without it a far ball paints over a near one and the object inverts.

The shape is a point table

A cube's eight corners plus its six face centers: legible when it turns, trivial to sort. A different shape is a different table, and the machinery is unchanged. Cost is a rotate, a divide and a small disc per point, so size is the knob.