Rhythm: pluck at both turning points by default
A new rhythm option plucks wherever x' crosses 0 in either direction, so
each swing plays its low and high end; it is now the default, ahead of
upward crossings only and the steady once-per-period beat.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 changed files+16−11
README.mdmodified+1−1View file
@@ -18,7 +18,7 @@ Static `index.html`, `style.css` and ES modules, no build step; fonts bundled un
1818 - **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).
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.
21-- **Rhythm**: *natural* (the default) 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. *Steady* plucks once per drive period, at the section point.
21+- **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.
2222 - **Parameters**: f₀ (negative: a double well), α, δ, F, Ω/2π, and the view's half-width in x. Presets: double well (islands in a sea; gentle drive with a thin chaotic layer; strong drive), pure cubic, hardening resonance island, and a damped strange attractor.
2323
2424 ## Physics and sound
app/index.htmlmodified+2−1View file
@@ -25,7 +25,8 @@
2525 <label class="row">
2626 <span>Rhythm</span>
2727 <select id="rhythm">
28- <option value="natural" selected>Natural: ẋ crosses 0 upward</option>
28+ <option value="both" selected>Natural: ẋ crosses 0 both ways</option>
29+ <option value="natural">Natural: ẋ crosses 0 upward</option>
2930 <option value="steady">Steady: each drive period</option>
3031 </select>
3132 </label>
app/main.jsmodified+13−9View file
@@ -14,7 +14,8 @@
1414 // - Rhythm 'natural' instead plays the motion in slowed time (still one
1515 // drive period per beat) and plucks wherever x' crosses 0 upward (the
1616 // left turning point of each swing), at that x: each orbit makes its own
17-// rhythm, regular on an island, irregular in the sea.
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.
1819 // - Changing a parameter or preset restarts everything from the same starts,
1920 // the clicked orbits included.
2021
@@ -113,15 +114,16 @@ const ringTime = () => Math.min(RING, 3 * noteDt());
113114 // last, notes }) still needed for the trail; notes: [{ t, x, v }]
114115 const newPlayhead = (x, v) => ({ s: { x, v, escaped: false }, queue: [] });
115116
116-// The upward crossings of x' = 0 along a drive period's path (N + 1 points,
117-// evenly spaced in time over dt from time t0), interpolated linearly.
118-function upwardCrossings(path, t0, dt) {
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).
120+function crossings(path, t0, dt, both) {
119121 const N = path.length / 2 - 1;
120122 const notes = [];
121123 for (let j = 1; j <= N; j++) {
122124 const v0 = path[2 * j - 1];
123125 const v1 = path[2 * j + 1];
124- if (v0 < 0 && v1 >= 0) {
126+ if ((v0 < 0 && v1 >= 0) || (both && v0 > 0 && v1 <= 0)) {
125127 const f = v0 / (v0 - v1);
126128 notes.push({ t: t0 + ((j - 1 + f) / N) * dt, x: path[2 * j - 2] + f * (path[2 * j] - path[2 * j - 2]), v: 0 });
127129 }
@@ -131,7 +133,8 @@ function upwardCrossings(path, t0, dt) {
131133
132134 // schedule the beats due within LOOKAHEAD: on each, every playhead advances
133135 // one drive period (keeping the path for the trail) and plucks its notes
134-// (steady: one at the section point; natural: at each upward x' = 0),
136+// (steady: one at the section point; natural: at each upward x' = 0;
137+// both: at each x' = 0),
135138 // softer the more orbits there are
136139 function schedule() {
137140 const now = clock();
@@ -141,7 +144,7 @@ function schedule() {
141144 if (!clicked.length) return;
142145 const scale = SCALES[$('scale').selectedIndex];
143146 const gain = 1 / Math.sqrt(clicked.length);
144- const natural = $('rhythm').value === 'natural';
147+ const rhythm = $('rhythm').value;
145148 const dt = noteDt();
146149 while (nextBeat < now + LOOKAHEAD) {
147150 for (const { ph, voice } of clicked) {
@@ -149,8 +152,9 @@ function schedule() {
149152 const { x, v } = ph.s;
150153 const path = new Float32Array(2 * (stepper.N + 1));
151154 stepper.step(ph.s, path);
152- // (natural: none in the period it escapes, whose path ends at rest)
153- const notes = !natural ? [{ t: nextBeat, x, v }] : ph.s.escaped ? [] : upwardCrossings(path, nextBeat, dt);
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');
154158 ph.queue.push({ time: nextBeat, path, last: ph.s.escaped, notes });
155159 if (soundOn && synth) {
156160 for (const n of notes) {