Patch Cables
- group .........
- Cursor and hover effects
- source ........
- https://ui.aryank.space/components/patch-cables
- markdown ......
- /lab/patch-cables.md
- human .........
- /lab/patch-cables
── WHAT_IT_IS ────────────────────────────────────────────────────────────────────────────────
A lattice of lime dots on slate that you play with the cursor. Hover and nearby dots fuse into gooey cables; drag to patch cables that fill with ink and carry signal beads from jack to jack. Every cable that closes plays a note on a pentatonic scale, through four synth voices with a shared delay and reverb. Generators can play it on their own, in time with one tempo. One WebGL2 shader and Web Audio, no dependencies.
── BEHAVIOUR ────────────────────────────────────────────────────────────────────────────────
* One shader draws the whole field
Dots sit on the even cells of a lattice and each cell owns one diagonal. A full-screen WebGL2 fragment shader reads two small state textures and draws dots, necks and signal beads as one signed distance field, joined with a C2 smooth union so the goo has no crease.
* Joins snap, and each join is a note
A spring per cell grows two stubs that meet in the middle. Past 0.42 of pull the cell snaps closed and holds until the pull drops under 0.2. When it closes past 0.52 it plays one note, at most one per frame and 140ms apart for Mist.
* Position picks the pitch
The note comes from (column + rows above the bottom × 2) mod 15 on G minor pentatonic from 98 Hz (Mist uses D major pentatonic), so any gesture stays in key. Pan follows the column.
* Audio starts on the first press
Browsers block sound before a gesture, so the AudioContext is created on the first pointer down in the canvas or a voice change.