2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>Double pendulum</title>
7 <style>
8 :root {
9 --bg: #f6f6f3;
10 --card: #ffffff;
11 --line: #e3e2dc;
12 --text: #23262b;
13 --muted: #7a7d82;
14 --accent: #2f5d8a;
15 --accent-soft: #e6eef6;
16 --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
17 --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
18 --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
19 }
20 * { box-sizing: border-box; }
21 body {
22 margin: 0;
23 background: var(--bg);
24 color: var(--text);
25 font: 14px/1.45 var(--sans);
26 }
27 main { max-width: 1040px; margin: 0 auto; padding: 28px 16px 48px; }
28 header { margin-bottom: 20px; }
29 h1 { font: 400 28px/1.2 var(--serif); margin: 0 0 4px; letter-spacing: 0.01em; }
30 .sub { margin: 0; color: var(--muted); }
31 .grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
32 @media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
33 .card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
34 .label {
35 font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
36 }
37 .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
38 .num { font: 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
39 .muted { color: var(--muted); font-size: 12px; }
41 canvas { display: block; }
42 canvas[hidden], figure[hidden], [hidden] { display: none ; }
43 #canvas { width: 100%; aspect-ratio: 1; }
45 input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 120px; margin: 0; }
46 select, input[type="number"] {
47 font: inherit; font-size: 13px; color: var(--text); background: #fff;
48 border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px;
49 }
50 input[type="number"] { width: 5.5em; font-family: var(--mono); }
51 button {
52 font: inherit; font-size: 13px; color: var(--text); background: #fff; cursor: pointer;
53 border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px;
54 }
55 button:hover { border-color: #c9c8c0; }
56 button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 76px; }
57 button.primary:hover { filter: brightness(1.08); }
58 button:disabled { color: #b5b5b0; cursor: default; }
59 button:disabled:hover { border-color: var(--line); }
60 button.mute { width: 36px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
61 button.mute svg { width: 18px; height: 18px; }
62 button.mute.audible { background: var(--accent-soft); border-color: #b9cde0; color: var(--accent); }
64 #controls { margin-top: 14px; }
65 #energy { min-width: 70px; }
66 #energy-value { min-width: 5.5em; text-align: right; }
67 #ghost-row { margin-top: 10px; min-height: 28px; }
68 #ghost-controls { flex: 1; }
69 #ghost-offset { max-width: 140px; min-width: 80px; }
70 #ghost-sep { width: 100%; }
72 details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
73 summary { cursor: pointer; color: var(--muted); font-size: 13px; list-style: none; }
74 summary::-webkit-details-marker { display: none; }
75 summary::before { content: "▸ "; }
76 details[open] summary::before { content: "▾ "; }
77 details#audio { border-top: 1px solid var(--line); padding-top: 16px; }
78 details#audio summary { display: flex; align-items: baseline; gap: 10px; }
79 details#audio summary .label { font-size: 12px; color: var(--text); }
80 details#audio[open] summary { margin-bottom: 14px; }
81 #param-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 16px; margin-top: 10px; }
82 #param-form label { display: grid; grid-template-columns: 1.6em 5.5em auto; align-items: center; gap: 6px; font-size: 13px; }
83 #param-form .unit { color: var(--muted); font-size: 12px; }
84 #param-actions { margin-top: 10px; }
85 #param-status { color: #a33; font-size: 12px; }
86 #params { margin-top: 10px; font: 12px/1.6 var(--mono); color: var(--muted); white-space: pre; overflow-x: auto; }
88 .chips { display: flex; flex-wrap: wrap; gap: 6px; }
89 .chip { position: relative; cursor: pointer; user-select: none; }
90 .chip input { position: absolute; opacity: 0; pointer-events: none; }
91 .chip span {
92 display: inline-block; font-size: 12px; padding: 3px 11px; border-radius: 999px;
93 border: 1px solid var(--line); color: var(--muted); background: #fff;
94 }
95 .chip:hover span { border-color: #c9c8c0; }
96 .chip input:checked + span { background: var(--accent-soft); border-color: #b9cde0; color: var(--accent); }
97 .chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
99 figure { margin: 14px 0 0; }
100 figure canvas { width: 100%; height: auto; border-radius: 4px; }
101 #scatter-fig figcaption { justify-content: space-between; flex-wrap: nowrap; }
102 figcaption { margin-top: 4px; }
103 #traces canvas, #audio-traces canvas { width: 100%; height: auto; margin-top: 12px; }
104 #plots-empty { margin: 14px 0 2px; }
106 #audio { margin-top: 16px; }
107 #audio .row + .row { margin-top: 12px; }
108 #audio label { display: flex; align-items: center; gap: 8px; }
109 #audio .grow { flex: 1; min-width: 220px; }
110 #volume { max-width: 110px; }
111 </style>
112 </head>
113 <body>
114 <main>
115 <header>
116 <h1>Double pendulum</h1>
117 <p class="sub">Raise the energy and listen for where the motion becomes chaotic.</p>
118 </header>
120 <div class="grid">
121 <section class="card">
122 <canvas id="canvas"></canvas>
123 <form id="controls" class="row">
124 <span class="label">Energy</span>
125 <input id="energy" type="range" value="50" min="0" max="120" step="0.1" aria-label="Energy" />
126 <span id="energy-value" class="num">50.0 J</span>
127 <button type="submit" class="primary" title="Start from hanging rest with this energy">Strike</button>
128 <button type="button" id="pause" disabled>Pause</button>
129 </form>
130 <div id="ghost-row" class="row">
131 <label class="chip" title="A second pendulum started with the outer arm offset by a tiny angle"><input id="ghost-toggle" type="checkbox" /><span>Ghost</span></label>
132 <span id="ghost-controls" class="row" hidden>
133 <span class="label">Offset</span>
134 <input id="ghost-offset" type="range" min="-12" max="-1" step="1" value="-10" aria-label="Ghost offset (power of ten)" />
135 <span id="ghost-offset-value" class="num"></span>
136 <button id="ghost-reset" type="button" title="Restart the ghost from the pendulum's current state">Reset</button>
137 </span>
138 <span id="ghost-sep" class="num muted"></span>
139 </div>
140 <details>
141 <summary>Parameters</summary>
142 <form id="param-form">
143 <label><span>m<sub>1</sub></span> <input id="p-m1" type="number" step="any" /> <span class="unit">kg</span></label>
144 <label><span>m<sub>2</sub></span> <input id="p-m2" type="number" step="any" /> <span class="unit">kg</span></label>
145 <label><span>l<sub>1</sub></span> <input id="p-l1" type="number" step="any" /> <span class="unit">m</span></label>
146 <label><span>l<sub>2</sub></span> <input id="p-l2" type="number" step="any" /> <span class="unit">m</span></label>
147 <label><span>g</span> <input id="p-g" type="number" step="any" /> <span class="unit">m/s²</span></label>
148 <label title="Amplitude decay time from drag on the bobs (all modes). 0 = no damping."><span>τ</span> <input id="p-tau" type="number" step="any" min="0" /> <span class="unit">s decay</span></label>
149 </form>
150 <div id="param-actions" class="row">
151 <button type="submit" form="param-form">Apply</button>
152 <label class="muted">Preset <select id="preset">
153 <option value="">custom</option>
154 <option value="equal">l2 = 1 m</option>
155 <option value="tenth">l2 = 1.5667 m</option>
156 <option value="golden">l2 = 2 m</option>
157 <option value="eightThirds">l2 = 2.1637 m</option>
158 <option value="twelfth">l2 = 3.2476 m</option>
159 <option value="doubleOctave">l2 = 6.886 m</option>
160 </select></label>
161 <span id="param-status"></span>
162 </div>
163 <div id="params"></div>
164 </details>
165 </section>
167 <section class="card">
168 <div class="chips" id="toggles">
169 <label class="chip"><input id="spec-toggle" type="checkbox" /><span>Spectrogram</span></label>
170 </div>
171 <p id="plots-empty" class="muted">Choose what to plot.</p>
172 <figure id="spec-fig" hidden>
173 <div id="spectrogram"></div>
174 <figcaption id="spec-label" class="muted"></figcaption>
175 </figure>
176 <div id="traces"></div>
177 </section>
178 </div>
180 <details class="card" id="audio">
181 <summary><span class="label">Sound</span><span class="muted">Hear the motion, sped up. Each Strike plays a note.</span></summary>
182 <div class="row">
183 <button id="mute" type="button" class="mute" title="Unmute" aria-label="Unmute"></button>
184 <label><span class="label">Sound of</span> <select id="signal"></select></label>
185 <label><span class="label">Volume</span> <input id="volume" type="range" min="0" max="1" step="0.01" value="0.5" /></label>
186 <span id="audio-chips" class="chips">
187 <label class="chip"><input id="audio-spec-toggle" type="checkbox" checked /><span>Spectrogram</span></label>
188 </span>
189 </div>
190 <div class="row">
191 <label class="grow"><span class="label">Pitch</span> <input id="pitch" type="range" min="0" max="1000" step="1" aria-label="Pitch of the lower mode" /></label>
192 <span id="pitch-value" class="num"></span>
193 </div>
194 <div class="row"><span id="audio-status" class="muted"></span></div>
195 <figure id="audio-spec-fig">
196 <div id="audio-spectrogram"></div>
197 <figcaption id="audio-spec-label" class="muted"></figcaption>
198 </figure>
199 <div id="audio-traces"></div>
200 <figure id="scatter-fig" hidden>
201 <div id="scatter"></div>
202 <figcaption class="muted row">
203 <span>Each point is a moment of a note: its energy and Lyapunov exponent. Color is time into the note on a log scale: red just after the strike, then amber, blue late. Earlier notes are faded; strike several times to build up the picture.</span>
204 <button id="scatter-clear" type="button">Clear</button>
205 </figcaption>
206 </figure>
207 </details>
208 </main>
209 <script type="module" src="/src/main.ts"></script>
210 </body>
211</html>