TruchetEffect
Source:
TruchetEffect.h
TruchetEffect¶
src/light/effects/TruchetEffect.h:33Inherits:
EffectBase
Effect: randomly-turned arc tiles that join into endless winding paths.

Randomly turned tiles with arcs at their edges join into continuous winding paths. The pattern looks designed, and nothing designed it. Nothing is stored either: this is one function of position and time, evaluated per pixel.
Prior art: Sebastien Truchet's tiling, revived by Cyril Smith in 1987. The shader form follows the standard fract, hash and smoothstep idiom.
Public Attributes¶
uint8_t bpm = 6
: How fast the pattern drifts.
uint8_t scale = 3
: Tiles across the short side.
uint8_t thickness = 60
: How fat the arcs are.
uint8_t softness = 40
: Edge softness, which is the anti-aliasing width.
uint8_t shuffle = 0
: Reshuffles which way the tiles face.
bool drift = true
: Slide the pattern rather than holding it still.
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 drift, the tile size, the arc shape and the shuffle.
virtual inline void tick() override
: Evaluate the tiling per pixel: which cell, which way it turns, and how near an arc.
More info¶
The three moves most shader effects are built from¶
Space folding: repeat chops the plane into cells and returns the position inside one. So the shader only has to draw a single tile, and the coordinate takes care of the hundreds.
Per-cell variation from position alone: hashInt on the cell index turns that tile. Being a pure function, tile (7, 3) is always the same tile, and two devices agree on it.
Distance plus smoothstep: each tile is two arcs drawn as the distance to a ring. The smoothstep across that distance is what stops a curve reading as a staircase.
Cost is two SDF evaluations and a hash per pixel, all integer, so any target runs it.