Field card
File: truchet-music.html
One idea: a circuit's length becomes the time between notes when a dot moves at constant speed and strikes once per lap. Turn a tile; hear connectivity change.
Companions: truchet-loops.html, for local turns changing global paths, and aperiodic-etude.html, for a visual and audible reading of the same mathematical object.
The instrument
A 4 × 4 Truchet board. Each tile connects its four edge midpoints in one of two ways. Native buttons turn tiles; arrow keys navigate and Enter/Space turn.
Visible semicircles pair the exposed ends around the frame. These returns are part of the instrument, making every route a closed circuit. This is an explicit boundary condition, not a claim that arbitrary finite Truchet paths close.
Three fixed hollow markers anchor C4, E4 and G4. A matching circle, diamond or square travels from each marker and plays that note on each return. Pitch and voice identity remain fixed when a tile turns. Interleaved colours indicate a circuit shared by more than one voice; the markers remain distinct.
All dots move at the same physical speed. A small tile arc takes a quarter beat; a semicircular return is twice as long and takes half a beat. The readout reports each voice's full lap in beats, including the returns.
The opening is the checked bitmask 12, with gates 4, 27, 10: routes of 8, 12, 20 quarter-arc units, hence 2, 3, 5 beats. The next simultaneous return is after 30 beats. These are computed, not editorial labels on a different pattern.
What is chosen, what is derived
The three pitches, synthesis envelope, four-arcs-per-beat mapping and return bends are compositional choices. The route memberships, lengths, durations and next shared return follow exactly from those choices and the tile arrangement.
This finite instrument repeats while its layout stays fixed. Its interest is changing rhythm by changing topology, not an aperiodicity claim. Turning one tile does not guarantee that a sounding circuit changes: some turns affect only silent paths. Several notes can end up on the same circuit and acquire the same period.
Each edit deliberately restarts the dots together. That gives a clear comparison of the new circuit periods and prevents a scheduled note from following an old route. Seamless rerouting of moving dots would be a separate design experiment.
Sound, clock and lifecycle
No libraries, samples, network requests, microphone or recording. Web Audio is created/resumed only by the Play button. Three decaying sine tones feed a volume control. Note scheduling uses the audio clock with a short lookahead; the moving dots use that clock and output timestamps where available, rather than counting animation frames. Missed strikes are skipped after a scheduler stall.
Pause suspends the audio context, preserving phase. Turning a tile or changing tempo cancels old scheduled strikes and restarts together; muting cancels that voice's queued sound. Leaving the tab pauses playback. Reduced motion replaces travelling dots with small sounding-marker fills. Controls remain usable with sound off; colour is paired with note names and marker shapes.
Audio API references: MDN best practices and output timestamps.
Verification
Run from the blog root:
node --test widget-studio/tests/truchet-music.test.mjs
Seven tests read the exact model script embedded in the HTML. They cover every 2 × 2 board, 512 varied 4 × 4 boards, edge coverage, route closure, true arc lengths, smooth seam tangents, all sixteen opening tile turns and their reversibility, fixed gate locations, audio/geometry return agreement at three tempos, and the minimality of the computed common return.
Browser checks also passed for the standalone page and the sandboxed inline copy: real Web Audio scheduling, a rendered offline waveform, play/pause/resume, live turns, voice muting, tempo/volume, keyboard navigation, hidden-tab pause, reopening after pagehide, reduced motion and a 320 px layout (tile targets remain over 55 px). The instrument's tone is intentionally plain; these checks establish operation, not a judgment about the resulting music.
Next questions, after listening
Is one strike per lap sufficiently expressive, or should users place extra strike markers along a circuit?
Would an infinite floor with locally traced loops be more interesting than the explicitly closed board? Open or unresolved paths need an honest sound rule.
Can live rerouting preserve a moving dot's position while making a changed rhythm understandable? The restart rule here makes that tradeoff inspectable.
Keep this a standalone study until the relationship earns a production component.