Optional click mode: replace the orbit instead of adding
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 changed files+25−4
README.mdmodified+1−1View file
@@ -15,7 +15,7 @@ Static `index.html`, `style.css` and ES modules, no build step; fonts bundled un
1515 ## What's in it
1616
1717 - **Poincaré section**: (x, ẋ) once per drive period, at drive phase 0. Seed orbits from the axes of the view fill it in live. Undamped, regular orbits draw closed curves (islands, island chains) and chaotic ones scatter over the sea. Damped, the seeds settle onto the attractors first.
18-- **Click** to add an orbit from that point (up to 8; click its start ring to remove it): its dots fill in (larger, brighter), and a playhead walks it one drive period per beat, with a fading trail of the continuous motion through each period and a ring at each return to the section. Changing a parameter or preset keeps them, restarted from the same (x, ẋ) under the new parameters. All the clicked orbits play together, on the same beat, each in its own voice (listed in the panel with its color; × removes it).
18+- **Click** to add an orbit from that point (up to 8; click its start ring to remove it; with *Clicks: replace the orbit*, each click starts a new orbit in place of the old ones, for quick exploring): its dots fill in (larger, brighter), and a playhead walks it one drive period per beat, with a fading trail of the continuous motion through each period and a ring at each return to the section. Changing a parameter or preset keeps them, restarted from the same (x, ẋ) under the new parameters. All the clicked orbits play together, on the same beat, each in its own voice (listed in the panel with its color; × removes it).
1919 - **Sound**: each return to the section plays a note, its pitch set by x (left to right across the view: C3 to C6), on a selectable scale (minor pentatonic by default; major pentatonic, major, minors, whole tone, chromatic, or continuous) in a selectable key (A by default). The key buttons keep the register (C3 to C6) and change which notes x snaps to, so switching key while playing shifts the harmony like a chord change. An island orbit plays a repeating pattern; a chaotic one wanders. Tempo sets drive periods per second (default 16, up to 40; the motion is slowed down to that), independent of the drive frequency.
2020 - **Voices**: the first orbit plays a harp; the next ones marimba, vibraphone, electric piano, music box, ocarina, pizzicato and kalimba (an orbit takes the first voice not in use). **Sustain** (0.1 to 4 s, default 2) sets how long every note rings, the same for all voices and pitches, so they differ only in timbre and attack, and all start equally loud.
2121 - **Rhythm**: *natural, upward* plucks wherever ẋ crosses 0 upward (the left turning point of each swing), at that x and at that moment in the slowed-down motion, so each orbit makes its own rhythm: a lilting, nearly regular one on an island, an uneven one in the sea, and several orbits make polyrhythms. *Both ways* (the default) also plucks at the right turning point (ẋ crossing 0 downward), so each swing plays its low and high end. *Steady* plucks once per drive period, at the section point.
app/index.htmlmodified+7−0View file
@@ -60,6 +60,13 @@
6060 </label>
6161 </div>
6262
63+ <label class="row click-mode">
64+ <span>Clicks</span>
65+ <select id="click-mode">
66+ <option value="add" selected>Add an orbit</option>
67+ <option value="replace">Replace the orbit</option>
68+ </select>
69+ </label>
6370 <ul id="orbit-list" class="orbit-list"></ul>
6471 <button id="clear" class="quiet">Clear orbits</button>
6572 </aside>
app/main.jsmodified+16−2View file
@@ -4,7 +4,8 @@
44 //
55 // - Seed orbits, started on the axes of the view at drive phase 0, fill the
66 // 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;
7+// - A click adds an orbit from that point (drive phase 0), up to MAX_CLICKED
8+// (or, with Clicks set to replace, takes the place of the clicked ones);
89 // clicking an orbit's start ring removes it. Its dots fill in fast and
910 // larger, and a playhead walks it one drive period per beat: a live trail
1011 // traces the motion through the period, and at each return to the section
@@ -537,6 +538,14 @@ function buildControls() {
537538 if (btn) removeOrbit(clicked.find((c) => String(c.hue) === btn.dataset.hue));
538539 });
539540
541+ const hintOut = () => {
542+ $('hint').textContent = $('click-mode').value === 'replace'
543+ ? 'Click to start an orbit · click its start ring to remove it'
544+ : 'Click to add orbits · click a start ring to remove it';
545+ };
546+ $('click-mode').addEventListener('change', hintOut);
547+ hintOut();
548+
540549 canvas.addEventListener('pointerdown', (e) => {
541550 const rect = canvas.getBoundingClientRect();
542551 const r = plotRect();
@@ -554,7 +563,12 @@ function buildControls() {
554563 }
555564 const x = ((px - r.x) / r.w * 2 - 1) * view.xr;
556565 const v = (1 - (py - r.y) / r.h * 2) * view.vr;
557- if (clicked.length >= MAX_CLICKED) removeOrbit(clicked[0]);
566+ if ($('click-mode').value === 'replace') {
567+ // the new orbit takes the place of all the clicked ones
568+ clicked = [];
569+ orbits = orbits.filter((o) => !o.clicked);
570+ clearDots([top]);
571+ } else if (clicked.length >= MAX_CLICKED) removeOrbit(clicked[0]);
558572 // the first voice no other orbit is playing
559573 const voice = VOICES.findIndex((_, i) => !clicked.some((c) => c.voice === i));
560574 const hue = (0.08 + hueCounter++ * 0.382) % 1;
app/style.cssmodified+1−1View file
@@ -69,7 +69,7 @@ h1 {
6969
7070 .sliders, .sound { display: flex; flex-direction: column; gap: 8px; }
7171
72-.sound { padding-top: 14px; border-top: 1px solid var(--line); }
72+.sound, .click-mode { padding-top: 14px; border-top: 1px solid var(--line); }
7373
7474 .row {
7575 display: grid;