Visualizations
469 / 500

469 · Sound

Music Box

A pinned brass drum plucks cantilever tines from a punched strip you can edit.

A walnut box holds a brass comb of 20 tines (G3 to E6 in C major) and a pinned drum, fed by a looping 64-row paper strip that is the drum's pin chart unrolled: every hole that reaches the slot is a pin, lifting its tine until the tine slips off and rings. Each tine is a clamped-free Euler-Bernoulli cantilever, so its partials sit at the roots of cos(bL) cosh(bL) = -1, at 1 : 6.27 : 17.55 : 34.39 times the fundamental, nowhere near the harmonic series, which is the music box's glassy sparkle. A released tine starts from the static tip-load shape, and projecting that shape onto the mode shapes gives each partial's amplitude; the card on the right replays the motion several hundred times slower, split into its modes, with the partials plotted against harmonic ticks. The sound is the same modal sum, weighted as velocity and with higher modes dying faster, through a small wooden body, while the autopilot punches the second voice of a two-part canon.

Try it. Click or drag on the strip to punch holes or patch them, and click or sweep across the tines to pluck them. Space stops and starts the crank, the arrow keys change the tempo, C clears the strip, R restores the canon, M mutes; sound starts on the first click.

  • Modal synthesis
  • Euler-Bernoulli cantilever
  • Mode shape projection
  • Inharmonic partials
  • Procedural wood textures
  • Web Audio

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a playable music box with JavaScript, the HTML canvas element and the Web Audio API. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window.
- Draw a comb of 15 brass tines side by side, tuned to a C major scale from C5 upward. Bass tines are longer.
- Above the comb, draw a paper strip as a grid: one column per tine, 32 rows. Clicking a cell punches or patches a hole. The strip scrolls toward the comb at a steady speed and loops.
- When a row of holes reaches the comb, pluck those tines. Create the AudioContext only on the first click.
- Synthesize each pluck as a few decaying sine waves. A tine is a cantilever beam clamped at one end, so its overtones are not 2f, 3f, 4f but 6.27f and 17.55f. Give each overtone a smaller amplitude and a faster decay than the fundamental.
- Make a plucked tine flash and shimmer for a moment.

Once that works, make it beautiful:
- Paint a warm wooden box and table with a simple procedural wood grain (stretched noise turned into rings), lit as if by a window.
- Draw the strip as cream paper with printed note lines, and the holes as dark slots with a lit lower edge.
- Show the tine bending: lift it slightly just before its hole arrives, then let it ring with a blur that fades.
- Pre-punch a short melody so it plays something nice before anyone touches it.

Explain the key ideas in short code comments, especially why the overtones are inharmonic. When you're done, tell me how to open it and suggest three directions I could take it next, such as a pinned cylinder view, a slow-motion side view of one tine split into its vibration modes, or loading a melody from text.
PreviousMode 7 TrackThe per-scanline floor trick of 16-bit kart racers, with a debug view of every row. NextImpossible RoomsA house that cannot exist: a ballroom in a wardrobe, a corridor longer inside than out.

Related visualizations

  • Plucked StringsSound Seven finite-difference strings to pluck, with live harmonics and slow-motion kinks.
  • Marimba Bar TunerPhysics Carve a rosewood bar while a finite element solver retunes its overtones to 1:4:10.
  • DrumheadSound A floor tom whose sound is sampled live from the 2D wave equation that draws its head.
  • Chladni PlateSound Sand dances into Chladni figures on a brass plate whose modes come from the Ritz method.
  • Dissonance CurveSound Plomp-Levelt roughness summed over every partial pair: where consonance comes from.
  • Phase MusicSound Two players loop one figure, one slightly faster, printing a moire record of the drift.
  • Spectrogram PainterSound Paint sound in time and frequency, then watch the real spectrogram of what you hear.
  • TonnetzSound Euler's lattice of tones, where chords flip like cards and the plane folds into a torus.
  • Birdsong SyrinxSound Birdsong from a two-knob nonlinear oscillator, printed live as an ink sonogram.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs