1// Islands in a sea of chaos: the Poincaré section of the driven Duffing
2// oscillator (js/duffing.js), filled in live, with clickable orbits and a
3// sonification (js/voices.js).
4//
5// - Seed orbits, started on the axes of the view at drive phase 0, fill the
6// section in the background, a few thousand points per frame.
7// - A click adds an orbit from that point (drive phase 0), up to MAX_CLICKED;
8// clicking an orbit's start ring removes it. Its dots fill in fast and
9// larger, and a playhead walks it one drive period per beat: a live trail
10// traces the motion through the period, and at each return to the section
11// a note is played, its pitch set by x (left to right over three octaves
12// of the chosen scale). All the clicked orbits play together, on the same
13// beat, each in its own voice (harp, marimba, ...), listed in the panel.
14// - Rhythm 'natural' instead plays the motion in slowed time (still one
15// drive period per beat) and plucks wherever x' crosses 0 upward (the
16// left turning point of each swing), at that x: each orbit makes its own
17// rhythm, regular on an island, irregular in the sea. 'both' plucks at
18// both turning points of each swing, where x' crosses 0 either way.
19// - Changing a parameter or preset restarts everything from the same starts,
20// the clicked orbits included.
22import { createStepper, physicsOf, X_MAX } from './js/duffing.js';
23import { createSynth, DEFAULT_KEY, DEFAULT_SCALE, KEYS, pitchOf, SCALES, SUSTAIN, VOICES } from './js/voices.js';
24import { PRESETS } from './js/presets.js';
26const SEEDS_X = 24; // seed orbits along x' = 0
27const SEEDS_V = 8; // and along x = 0
28const SEED_POINTS = 1500;
29const CLICK_POINTS = 4000;
30const CLICK_PER_FRAME = 40; // so a clicked orbit visibly grows
31const MAX_CLICKED = 8;
32const HIT_RADIUS = 9; // px: a click this close to a start ring removes it
33const FRAME_BUDGET = 7; // ms of integration per frame
34const TAIL = 2; // trail length, in drive periods
35const LOOKAHEAD = 0.12; // s of notes scheduled ahead
36const RING = 0.35; // s a pluck's ring takes to fade (at most 3 beats)
37const MARGIN = { left: 56, right: 12, top: 12, bottom: 34 };
39const SLIDERS = [
40 { name: 'freq', label: 'f<sub>0</sub>', unit: 'Hz', min: -1000, max: 1000, step: 5, fmt: (v) => `${v < 0 ? '−' : ''}${Math.abs(v)} Hz` },
41 { name: 'alpha', label: 'α', min: -5, max: 10, step: 0.1, scale: 1e7, fmt: (v) => `${v.toFixed(1)}·10⁷` },
42 { name: 'delta', label: 'δ', min: 0, max: 50, step: 0.5, fmt: (v) => `${v.toFixed(1)} s⁻¹` },
43 { name: 'F', label: 'F', min: 0, max: 30, step: 0.1, scale: 1e4, fmt: (v) => `${v.toFixed(1)}·10⁴` },
44 { name: 'drive', label: 'Ω / 2π', min: 20, max: 2000, step: 5, fmt: (v) => `${v} Hz` },
45 { name: 'view', label: 'View ±x', min: 0.1, max: X_MAX, step: 0.05, fmt: (v) => v.toFixed(2) },
46];
48const $ = (id) => document.getElementById(id);
49const canvas = $('plot');
50const ctx = canvas.getContext('2d');
51// the section points, accumulated: seed orbits, and clicked ones on top
52const dots = document.createElement('canvas');
53const top = document.createElement('canvas');
54const layers = [dots, top];
56let params = { ...PRESETS[0].params };
57let stepper;
58let view; // { xr, vr }: half-ranges of x and x'
59let orbits = []; // seed and clicked orbits
60let clicked = []; // clicked orbits: { x, v, hue, voice, ph }, ph its playhead
61let nextBeat = 0; // clock time of the next beat not yet scheduled
62let synth = null;
63let key = DEFAULT_KEY; // 0 = C, ..., 11 = B
64let soundOn = false;
65let hueCounter = 0;
66let theme;
68// ---- physics ---------------------------------------------------------------
70// x' half-range: the speed at the bottom of the well of a free orbit that
71// just reaches x = +/-xr, so the view frames the motions of that size
72function speedRange(p, xr) {
73 const V = (x) => 0.5 * p.omega2 * x * x + 0.25 * p.alpha * x ** 4;
74 const vMin = p.omega2 < 0 && p.alpha > 0 ? -(p.omega2 ** 2) / (4 * p.alpha) : 0;
75 const v = Math.sqrt(Math.max(0, 2 * (V(xr) - vMin)));
76 return Math.max(v, 0.3 * xr * p.Omega, 1);
77}
79// skip: drive periods to run before recording (a seed's transient)
80function newOrbit(x, v, cap, hue, isClicked, skip = 0) {
81 return { x0: x, v0: v, s: { x, v, escaped: false }, pts: new Float32Array(2 * cap), n: 0, cap, hue, clicked: isClicked, skip };
82}
84function reset() {
85 const p = physicsOf(params);
86 stepper = createStepper(p);
87 view = { xr: params.view, vr: speedRange(p, params.view) };
88 // damped: the seeds settle onto the attractors before they are drawn,
89 // for about 5 / delta (clicked orbits show the way in)
90 const skip = p.delta > 0 ? Math.min(5000, Math.ceil((5 / p.delta) / stepper.T)) : 0;
91 orbits = [];
92 for (let i = 0; i < SEEDS_X; i++) {
93 const x = view.xr * (-1 + (2 * (i + 0.5)) / SEEDS_X);
94 orbits.push(newOrbit(x, 0, SEED_POINTS, (i * 0.618) % 1, false, skip));
95 }
96 for (let i = 0; i < SEEDS_V; i++) {
97 const v = 0.9 * view.vr * (-1 + (2 * (i + 0.5)) / SEEDS_V);
98 orbits.push(newOrbit(0, v, SEED_POINTS, ((i + SEEDS_X) * 0.618) % 1, false, skip));
99 }
100 for (const c of clicked) {
101 orbits.unshift(newOrbit(c.x, c.v, CLICK_POINTS, c.hue, true));
102 c.ph = newPlayhead(c.x, c.v);
103 }
104 clearDots();
105}
107// ---- playhead and sound -----------------------------------------------------
109const clock = () => (synth ? synth.ctx.currentTime : performance.now() / 1000);
110const noteDt = () => 1 / Number($('tempo').value);
111const ringTime = () => Math.min(RING, 3 * noteDt());
113// a playhead: the orbit's state, and its scheduled beats ({ time, path,
114// last, notes }) still needed for the trail; notes: [{ t, x, v }]
115const newPlayhead = (x, v) => ({ s: { x, v, escaped: false }, queue: [] });
117// The crossings of x' = 0 along a drive period's path (N + 1 points, evenly
118// spaced in time over dt from time t0), interpolated linearly: upward only
119// (from x' < 0 to x' >= 0), or both ways (also from x' > 0 to x' <= 0).
120function crossings(path, t0, dt, both) {
121 const N = path.length / 2 - 1;
122 const notes = [];
123 for (let j = 1; j <= N; j++) {
124 const v0 = path[2 * j - 1];
125 const v1 = path[2 * j + 1];
126 if ((v0 < 0 && v1 >= 0) || (both && v0 > 0 && v1 <= 0)) {
127 const f = v0 / (v0 - v1);
128 notes.push({ t: t0 + ((j - 1 + f) / N) * dt, x: path[2 * j - 2] + f * (path[2 * j] - path[2 * j - 2]), v: 0 });
129 }
130 }
131 return notes;
132}
134// schedule the beats due within LOOKAHEAD: on each, every playhead advances
135// one drive period (keeping the path for the trail) and plucks its notes
136// (steady: one at the section point; natural: at each upward x' = 0;
137// both: at each x' = 0),
138// softer the more orbits there are
139function schedule() {
140 const now = clock();
141 // fallen behind (a stalled frame, a hidden tab), or nothing playing: carry
142 // on from now rather than play the missed notes in a burst
143 if (nextBeat < now) nextBeat = now + 0.02;
144 if (!clicked.length) return;
145 const scale = SCALES[$('scale').selectedIndex];
146 const gain = 1 / Math.sqrt(clicked.length);
147 const rhythm = $('rhythm').value;
148 const dt = noteDt();
149 while (nextBeat < now + LOOKAHEAD) {
150 for (const { ph, voice } of clicked) {
151 if (ph.s.escaped) continue;
152 const { x, v } = ph.s;
153 const path = new Float32Array(2 * (stepper.N + 1));
154 stepper.step(ph.s, path);
155 // (at crossings: none in the period it escapes, whose path ends at rest)
156 const notes = rhythm === 'steady' ? [{ t: nextBeat, x, v }]
157 : ph.s.escaped ? [] : crossings(path, nextBeat, dt, rhythm === 'both');
158 ph.queue.push({ time: nextBeat, path, last: ph.s.escaped, notes });
159 if (soundOn && synth) {
160 for (const n of notes) {
161 const u = (n.x / view.xr + 1) / 2;
162 synth.play(voice, pitchOf(u, scale, key), n.t, Math.max(-1, Math.min(1, 1.4 * u - 0.7)), gain);
163 }
164 }
165 }
166 nextBeat += dt;
167 }
168 const keep = Math.max((TAIL + 1) * dt, ringTime() + dt);
169 for (const { ph } of clicked) {
170 while (ph.queue.length > 1 && ph.queue[1].time < now - keep) ph.queue.shift();
171 }
172}
174function setSound(on) {
175 soundOn = on;
176 const btn = $('sound');
177 btn.setAttribute('aria-pressed', on);
178 btn.textContent = on ? '♪ Sound on' : '♪ Sound off';
179 if (on && !synth) {
180 // the clock switches to the audio context's
181 synth = createSynth();
182 synth.setSustain(Number($('sustain').value));
183 for (const { ph } of clicked) ph.queue = [];
184 nextBeat = 0;
185 }
186 if (synth) {
187 synth.ctx.resume();
188 synth.setVolume(on ? Number($('volume').value) : 0);
189 }
190}
192// ---- drawing -----------------------------------------------------------------
194function readTheme() {
195 const cs = getComputedStyle(document.documentElement);
196 theme = {
197 bg: cs.getPropertyValue('--bg').trim(),
198 fg: cs.getPropertyValue('--fg').trim(),
199 muted: cs.getPropertyValue('--muted').trim(),
200 line: cs.getPropertyValue('--line').trim(),
201 accent: cs.getPropertyValue('--accent').trim(),
202 light: cs.getPropertyValue('--dot-light').trim(),
203 };
204}
206const orbitColor = (hue, clickedOrbit, alpha = 1) =>
207 `hsla(${Math.round(hue * 360)}, ${clickedOrbit ? 85 : 50}%, ${theme.light}, ${alpha})`;
209function plotRect() {
210 const dpr = devicePixelRatio || 1;
211 const w = canvas.width / dpr;
212 const h = canvas.height / dpr;
213 return { x: MARGIN.left, y: MARGIN.top, w: Math.max(10, w - MARGIN.left - MARGIN.right), h: Math.max(10, h - MARGIN.top - MARGIN.bottom) };
214}
216const toPx = (r, x, v) => [r.x + ((x / view.xr + 1) / 2) * r.w, r.y + ((1 - v / view.vr) / 2) * r.h];
218function drawPoints(o, from) {
219 const r = plotRect();
220 const dctx = (o.clicked ? top : dots).getContext('2d');
221 dctx.fillStyle = orbitColor(o.hue, o.clicked, o.clicked ? 0.95 : 0.7);
222 const size = o.clicked ? 2.2 : 1.4;
223 for (let i = from; i < o.n; i++) {
224 const [px, py] = toPx(r, o.pts[2 * i], o.pts[2 * i + 1]);
225 dctx.fillRect(px - size / 2, py - size / 2, size, size);
226 }
227}
229function clearDots(which = layers) {
230 const dpr = devicePixelRatio || 1;
231 for (const layer of which) {
232 const c = layer.getContext('2d');
233 c.setTransform(1, 0, 0, 1, 0, 0);
234 c.clearRect(0, 0, layer.width, layer.height);
235 c.setTransform(dpr, 0, 0, dpr, 0, 0);
236 }
237}
239function resize() {
240 const dpr = devicePixelRatio || 1;
241 const { width, height } = canvas.getBoundingClientRect();
242 canvas.width = dots.width = top.width = Math.round(width * dpr);
243 canvas.height = dots.height = top.height = Math.round(height * dpr);
244 clearDots();
245 for (const o of orbits) drawPoints(o, 0);
246}
248// advance the orbits within the frame's budget, drawing their new points
249function fill() {
250 const deadline = performance.now() + FRAME_BUDGET;
251 const advance = (o, count) => {
252 const from = o.n;
253 for (let k = 0; k < count && o.n < o.cap && !o.s.escaped; k++) {
254 stepper.step(o.s);
255 if (o.s.escaped) break;
256 if (o.skip > 0) { o.skip--; continue; }
257 o.pts[2 * o.n] = o.s.x;
258 o.pts[2 * o.n + 1] = o.s.v;
259 o.n++;
260 }
261 drawPoints(o, from);
262 };
263 for (const o of orbits) if (o.clicked) advance(o, CLICK_PER_FRAME);
264 let busy = true;
265 while (busy && performance.now() < deadline) {
266 busy = false;
267 for (const o of orbits) {
268 if (o.clicked || o.n >= o.cap || o.s.escaped) continue;
269 advance(o, 10);
270 busy = true;
271 }
272 }
273}
275function drawAxes(r) {
276 ctx.strokeStyle = theme.line;
277 ctx.lineWidth = 1;
278 ctx.strokeRect(r.x + 0.5, r.y + 0.5, r.w - 1, r.h - 1);
279 ctx.beginPath();
280 ctx.moveTo(r.x + r.w / 2, r.y);
281 ctx.lineTo(r.x + r.w / 2, r.y + r.h);
282 ctx.moveTo(r.x, r.y + r.h / 2);
283 ctx.lineTo(r.x + r.w, r.y + r.h / 2);
284 ctx.stroke();
285 ctx.fillStyle = theme.muted;
286 ctx.font = '13px "Hanken Grotesk", system-ui, sans-serif';
287 ctx.textBaseline = 'top';
288 ctx.textAlign = 'left';
289 ctx.fillText(`−${view.xr.toFixed(2)}`, r.x, r.y + r.h + 6);
290 ctx.textAlign = 'right';
291 ctx.fillText(view.xr.toFixed(2), r.x + r.w, r.y + r.h + 6);
292 ctx.textAlign = 'center';
293 ctx.fillText('displacement x', r.x + r.w / 2, r.y + r.h + 6);
294 ctx.save();
295 ctx.translate(r.x - 8, r.y + r.h / 2);
296 ctx.rotate(-Math.PI / 2);
297 ctx.textBaseline = 'bottom';
298 ctx.fillText('velocity ẋ (s⁻¹)', 0, 0);
299 ctx.textAlign = 'right';
300 ctx.fillText(`${Math.round(view.vr)}`, r.h / 2, 0);
301 ctx.textAlign = 'left';
302 ctx.fillText(`−${Math.round(view.vr)}`, -r.h / 2, 0);
303 ctx.restore();
304}
306function drawPlayhead(r, ph, hue) {
307 if (!ph.queue.length) return;
308 const now = clock();
309 const dt = noteDt();
310 const N = stepper.N;
311 const q = ph.queue;
312 let cur = -1;
313 for (let k = 0; k < q.length; k++) if (q[k].time <= now) cur = k;
314 if (cur < 0) return;
315 ctx.save();
316 ctx.beginPath();
317 ctx.rect(r.x, r.y, r.w, r.h);
318 ctx.clip();
319 ctx.lineWidth = 1.6;
320 ctx.lineCap = 'round';
321 ctx.lineJoin = 'round';
322 const CHUNK = Math.max(4, Math.ceil(N / 24));
323 let head = null;
324 for (let k = 0; k <= cur; k++) {
325 const e = q[k];
326 const span = q[k + 1] ? q[k + 1].time - e.time : dt;
327 const f = Math.min(1, (now - e.time) / span);
328 const end = Math.floor(f * N);
329 for (let j0 = 0; j0 < end; j0 += CHUNK) {
330 const age = (now - (e.time + (j0 / N) * span)) / dt;
331 const alpha = 1 - age / TAIL;
332 if (alpha <= 0) continue;
333 ctx.strokeStyle = orbitColor(hue, true, 0.85 * alpha);
334 ctx.beginPath();
335 for (let j = j0; j <= Math.min(end, j0 + CHUNK); j++) {
336 const [px, py] = toPx(r, e.path[2 * j], e.path[2 * j + 1]);
337 if (j === j0) ctx.moveTo(px, py);
338 else ctx.lineTo(px, py);
339 }
340 ctx.stroke();
341 }
342 if (k === cur) {
343 const j = Math.min(N, f * N);
344 const i0 = Math.floor(j);
345 const i1 = Math.min(N, i0 + 1);
346 const w = j - i0;
347 head = toPx(r, (1 - w) * e.path[2 * i0] + w * e.path[2 * i1], (1 - w) * e.path[2 * i0 + 1] + w * e.path[2 * i1 + 1]);
348 if (e.last) head = null;
349 }
350 // each pluck: a ring growing and fading where it was played
351 for (const n of e.notes) {
352 const g = (now - n.t) / ringTime();
353 if (g < 0 || g >= 1) continue;
354 const [sx, sy] = toPx(r, n.x, n.v);
355 ctx.strokeStyle = orbitColor(hue, true);
356 ctx.globalAlpha = 1 - g;
357 ctx.lineWidth = 2;
358 ctx.beginPath();
359 ctx.arc(sx, sy, 4 + 14 * g, 0, 2 * Math.PI);
360 ctx.stroke();
361 ctx.globalAlpha = 1;
362 }
363 }
364 if (head) {
365 ctx.fillStyle = orbitColor(hue, true);
366 ctx.beginPath();
367 ctx.arc(head[0], head[1], 4.5, 0, 2 * Math.PI);
368 ctx.fill();
369 }
370 ctx.restore();
371}
373function drawStarts(r) {
374 for (const o of orbits) {
375 if (!o.clicked) continue;
376 const [px, py] = toPx(r, o.x0, o.v0);
377 ctx.strokeStyle = orbitColor(o.hue, true);
378 ctx.lineWidth = 1.5;
379 ctx.beginPath();
380 if (o.s.escaped) {
381 // escaped: a cross at its start
382 ctx.moveTo(px - 5, py - 5); ctx.lineTo(px + 5, py + 5);
383 ctx.moveTo(px + 5, py - 5); ctx.lineTo(px - 5, py + 5);
384 } else {
385 ctx.arc(px, py, 5, 0, 2 * Math.PI);
386 }
387 ctx.stroke();
388 }
389}
391function frame() {
392 requestAnimationFrame(frame);
393 if (!canvas.width || !canvas.height) return;
394 fill();
395 schedule();
396 const dpr = devicePixelRatio || 1;
397 const r = plotRect();
398 ctx.setTransform(1, 0, 0, 1, 0, 0);
399 ctx.fillStyle = theme.bg;
400 ctx.fillRect(0, 0, canvas.width, canvas.height);
401 ctx.drawImage(dots, 0, 0);
402 ctx.drawImage(top, 0, 0);
403 ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
404 drawAxes(r);
405 drawStarts(r);
406 for (const c of clicked) drawPlayhead(r, c.ph, c.hue);
407}
409// ---- controls ----------------------------------------------------------------
411function buildControls() {
412 const presetSel = $('preset');
413 presetSel.innerHTML = PRESETS.map((pr, i) => `<option value="${i}">${pr.name}</option>`).join('')
414 + '<option value="custom" hidden>Custom</option>';
416 $('sliders').innerHTML = SLIDERS.map((s) => `
417 <label class="row">
418 <span>${s.label}</span>
419 <input type="range" id="s-${s.name}" min="${s.min}" max="${s.max}" step="${s.step}">
420 <output id="o-${s.name}"></output>
421 </label>`).join('');
423 const show = () => {
424 for (const s of SLIDERS) {
425 const v = params[s.name] / (s.scale ?? 1);
426 $(`s-${s.name}`).value = v;
427 $(`o-${s.name}`).textContent = s.fmt(Number($(`s-${s.name}`).value));
428 }
429 };
430 for (const s of SLIDERS) {
431 $(`s-${s.name}`).addEventListener('input', (e) => {
432 params[s.name] = Number(e.target.value) * (s.scale ?? 1);
433 $(`o-${s.name}`).textContent = s.fmt(Number(e.target.value));
434 presetSel.value = 'custom';
435 reset();
436 });
437 }
438 presetSel.addEventListener('change', () => {
439 if (presetSel.value === 'custom') return;
440 // the clicked orbits stay, restarted from the same (x, x') under the new
441 // parameters (a start outside the new view still plays; its chip in the
442 // legend removes it)
443 params = { ...PRESETS[presetSel.value].params };
444 show();
445 reset();
446 });
447 show();
449 $('scale').innerHTML = SCALES.map((s) => `<option${s.name === DEFAULT_SCALE ? ' selected' : ''}>${s.name}</option>`).join('');
450 $('keys').innerHTML = KEYS.map((k, i) => `<button data-key="${i}" aria-pressed="${i === key}">${k}</button>`).join('');
451 $('keys').addEventListener('click', (e) => {
452 const btn = e.target.closest('button[data-key]');
453 if (!btn) return;
454 key = Number(btn.dataset.key);
455 for (const b of $('keys').children) b.setAttribute('aria-pressed', b === btn);
456 });
457 const sus = $('sustain');
458 Object.assign(sus, { min: SUSTAIN.min, max: SUSTAIN.max, step: SUSTAIN.step, value: SUSTAIN.default });
459 const susOut = () => { sus.nextElementSibling.textContent = `${Number(sus.value).toFixed(1)} s`; };
460 sus.addEventListener('input', () => {
461 susOut();
462 synth?.setSustain(Number(sus.value));
463 });
464 susOut();
465 const tempoOut = () => { $('tempo-out').textContent = `${$('tempo').value} /s`; };
466 $('tempo').addEventListener('input', tempoOut);
467 tempoOut();
468 const vol = $('volume');
469 const volOut = () => { vol.nextElementSibling.textContent = `${Math.round(100 * vol.value)}%`; };
470 vol.addEventListener('input', () => {
471 volOut();
472 if (synth && soundOn) synth.setVolume(Number(vol.value));
473 });
474 volOut();
475 $('sound').addEventListener('click', () => setSound(!soundOn));
476 $('clear').addEventListener('click', () => {
477 clicked = [];
478 reset();
479 renderLegend();
480 });
481 $('orbit-list').addEventListener('click', (e) => {
482 const btn = e.target.closest('button[data-hue]');
483 if (btn) removeOrbit(clicked.find((c) => String(c.hue) === btn.dataset.hue));
484 });
486 canvas.addEventListener('pointerdown', (e) => {
487 const rect = canvas.getBoundingClientRect();
488 const r = plotRect();
489 const px = e.clientX - rect.left;
490 const py = e.clientY - rect.top;
491 if (px < r.x || px > r.x + r.w || py < r.y || py > r.y + r.h) return;
492 // on a start ring: remove that orbit; otherwise add one from here
493 const hit = clicked.find((c) => {
494 const [cx, cy] = toPx(r, c.x, c.v);
495 return Math.hypot(cx - px, cy - py) <= HIT_RADIUS;
496 });
497 if (hit) {
498 removeOrbit(hit);
499 return;
500 }
501 const x = ((px - r.x) / r.w * 2 - 1) * view.xr;
502 const v = (1 - (py - r.y) / r.h * 2) * view.vr;
503 if (clicked.length >= MAX_CLICKED) removeOrbit(clicked[0]);
504 // the first voice no other orbit is playing
505 const voice = VOICES.findIndex((_, i) => !clicked.some((c) => c.voice === i));
506 const hue = (0.08 + hueCounter++ * 0.382) % 1;
507 clicked.push({ x, v, hue, voice, ph: newPlayhead(x, v) });
508 orbits.unshift(newOrbit(x, v, CLICK_POINTS, hue, true));
509 renderLegend();
510 });
511}
513function removeOrbit(c) {
514 if (!c) return;
515 clicked = clicked.filter((q) => q !== c);
516 orbits = orbits.filter((o) => !o.clicked || o.hue !== c.hue);
517 // redraw the clicked layer, so its dots go
518 clearDots([top]);
519 for (const o of orbits) if (o.clicked) drawPoints(o, 0);
520 renderLegend();
521}
523// the playing orbits: their color and voice, and a button to remove each
524function renderLegend() {
525 $('orbit-list').innerHTML = clicked.map((c) => `
526 <li>
527 <span class="swatch" style="background: ${orbitColor(c.hue, true)}"></span>
528 ${VOICES[c.voice].name}
529 <button data-hue="${c.hue}" aria-label="Remove the ${VOICES[c.voice].name} orbit">×</button>
530 </li>`).join('');
531}
533readTheme();
534matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { readTheme(); resize(); renderLegend(); });
535buildControls();
536reset();
537new ResizeObserver(resize).observe(canvas);
538resize();
539requestAnimationFrame(frame);