Skip to content
← Selected work
2026

Chordline

Melodies drawn by a bouncing ball

A ball bounces inside a shape and every wall hit lands exactly on a note of the melody, so its path draws a pattern as the tune plays. Built-in tunes, your own MIDI files or a piano-roll editor; ring, sphere, cube and more; share links and video export.

  • TypeScript
  • Three.js
  • Tone.js
  • Vite
  • Vitest
Chordline — Melodies drawn by a bouncing ball

Context

Chordline is a toy for watching music. A ball bounces inside a shape, every wall hit lands exactly on a note of the melody, and the ball's path draws a pattern as the tune plays. Play one of the built-in public-domain tunes, open or drop your own MIDI file (one ball per track if you like), or write a melody in the piano-roll editor.

The problem

Real physics cannot promise the ball reaches a wall on the beat. And anything that plays sound against moving pictures drifts unless both run on the same clock, so pause, seek and tempo changes become special cases.

Approach

The path is choreographed, not simulated: it is computed backwards from the melody. A melody becomes a list of onsets, and for each gap between them the planner picks a boundary point whose distance from the last hit matches speed times gap, so each flight is a straight line lasting exactly that gap. A seed steers the leftover choices, so one melody has many patterns and each seed always gives the same one. The planner is pure and works in 3D vectors: a shape only answers where a ray from the centre meets its boundary, so the sphere, cube, tetrahedron and ellipsoid needed no planner changes. Tone.js schedules the notes, and each frame Three.js draws the instant the listener is hearing, so nothing on screen keeps its own time.

Securing it

Everything runs in the browser, with no server. The address bar is always a link to the current pattern, and Record saves the piece as a video, including 9:16 for Shorts, Reels or TikTok. Tests cover the planner's timing and containment on every shape, MIDI clean-up and share links, and run before every build. The piano samples are credited with their licence (Salamander Grand Piano, CC BY 3.0).

What shipped

Live at chordline-nine.vercel.app, with source on GitHub. Known gaps, from its README: long MIDI files (thousands of notes) pause briefly while the path is re-planned, and audio-to-picture sync hasn't been checked by ear on many devices yet.