Visualizations
239 / 500

239 · Physics

Marimba Bar Tuner

Carve a rosewood bar while a finite element solver retunes its overtones to 1:4:10.

The bar is a free-free Euler-Bernoulli beam split into 60 cubic Hermite elements, whose stiffness follows the cube of the local thickness and whose mass follows the thickness, so the eigenproblem K v = w^2 M v changes with every stroke of the gouge. Subspace iteration on the banded matrices (a banded Cholesky factor, eight vectors, a Rayleigh-Ritz step solved with Jacobi rotations), warm-started from the previous frame, keeps up with the carving in a fraction of a millisecond. A plain bar rings at 1 : 2.76 : 5.40; arching the underside pulls the first overtone up to two octaves and the second to 10 times the fundamental, the marimba maker's target, and the ladder at the top shows the ratios sliding there while the mode shapes and their nodes animate above the bar. The strips under the bar are the exact sensitivity of each mode to removing wood at each point, the suspension holes follow the first mode's nodes, and the autopilot carves toward an arch found by Nelder-Mead on this same model, lands within a few cents of G3 at 1 : 4 : 10, then plays the finished bar with a mallet.

Try it. Drag along the underside to carve with a gouge, and click above the bar to strike it with a mallet and hear exactly the modes you carved. Space strikes the center, U undoes a stroke, R starts a fresh blank, M mutes; sound starts on the first click.

  • Finite element method
  • Hermite beam elements
  • Subspace iteration
  • Eigenvalue sensitivity
  • Modal synthesis
  • Nelder-Mead optimization

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 marimba bar tuner with JavaScript and the HTML canvas element: carve the underside of a wooden bar and watch its vibration modes change. 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.
- Model the bar as a beam 0.38 m long, 24 mm thick, with a thickness value at each of 40 points along its length. Draw it in side view, drawn twice as tall as it really is, with its underside following the thickness.
- Let the user drag along the underside to carve: lower the thickness under the pointer to the pointer's height, never below a minimum.
- Compute the bar's first three bending modes with the finite element method: 40 Euler-Bernoulli beam elements with two unknowns per node (deflection and slope), stiffness growing with thickness cubed and mass with thickness. Both ends are free. Solve the eigenproblem K v = w^2 M v with a few steps of inverse iteration with deflation, skipping the two rigid-body modes at zero.
- Draw the three mode shapes above the bar and show their frequencies and the ratios f2 / f1 and f3 / f1. A plain bar gives about 2.76 and 5.40.

Once that works, make it beautiful:
- Give the bar a rosewood texture and a warm background.
- Show the marimba maker's target: overtones at 4 and 10 times the fundamental, with markers that slide toward them as you carve.
- Click above the bar to strike it and play the three modes as decaying sine waves with the Web Audio API, creating the AudioContext on the first click.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as showing where removing wood lowers each mode, an undo button, or an automatic carver that optimizes the arch.
PreviousAnamorphic MirrorA wildly warped drawing that a chrome cylinder turns back into a picture. NextTuring PatternsTwo chemicals react and diffuse into coral, spots and stripes.

Related visualizations

  • Music BoxSound A pinned brass drum plucks cantilever tines from a punched strip you can edit.
  • Chladni PlateSound Sand dances into Chladni figures on a brass plate whose modes come from the Ritz method.
  • Plucked StringsSound Seven finite-difference strings to pluck, with live harmonics and slow-motion kinks.
  • PhotoelasticityPhysics Clear plastic parts under load light up with stress fringes between polarizers.
  • Wind HarpPhysics An Aeolian harp on a misty hill: vortex shedding picks the harmonic each string sings.
  • Laser ModesPhysics Hermite-Gauss grids, donuts and spinning vortex beams from a two-mirror laser.
  • Missing FundamentalIllusions Peel a note's harmonics away, fundamental first, and the heard pitch refuses to move.
  • Bowed StringPhysics Helmholtz motion on a bowed violin string, with a Schelleng diagram measured live.
  • TonnetzSound Euler's lattice of tones, where chords flip like cards and the plane folds into a torus.

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

← More from Emergent Mind Labs