← Feed
Link15 Nov 2018Rigs & DIYScience

The vanilla-JavaScript Chladni simulation people keep re-finding

Lucio Paiva's 2018 demo is small, fast and readable, and explains its own optimisation tricks.

Open at github.com ↗GitHub · 4 min

This is the browser Chladni simulation that most people encounter first. It cycles through random square-plate patterns using the standard superposition, written as cos(nπx/L)cos(mπy/L) − cos(mπx/L)cos(nπy/L), and lets particles settle onto the nodal lines.

The interesting part is the engineering. Rather than recompute the field every frame, it evaluates the pattern once per cycle in a web worker and pre-computes a gradient field, so each particle can look up its direction cheaply. That is exactly the trick you want if you are porting this idea to a microcontroller or an LED matrix where per-frame maths is expensive.

It is old: created in November 2018 and last pushed in March 2020, with 62 stars and no declared licence, which means you should ask before reusing the code commercially. The live demo runs at luciopaiva.com/chladni.

More from the feed