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 chaos</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: 16px; }
29 h1 { font: 400 28px/1.2 var(--serif); margin: 0 0 4px; letter-spacing: 0.01em; }
30 .grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
31 @media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
32 .card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
33 .label {
34 font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
35 }
36 .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
37 .num { font: 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
38 .muted { color: var(--muted); font-size: 12px; }
40 canvas { display: block; }
41 canvas[hidden], figure[hidden], [hidden] { display: none ; }
42 #canvas { width: 100%; aspect-ratio: 1; }
44 input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 120px; margin: 0; }
45 select, input[type="number"] {
46 font: inherit; font-size: 13px; color: var(--text); background: #fff;
47 border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px;
48 }
49 input[type="number"] { width: 5.5em; font-family: var(--mono); }
50 button {
51 font: inherit; font-size: 13px; color: var(--text); background: #fff; cursor: pointer;
52 border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px;
53 }
54 button:hover { border-color: #c9c8c0; }
55 button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 76px; }
56 button.primary:hover { filter: brightness(1.08); }
57 button:disabled { color: #b5b5b0; cursor: default; }
58 button:disabled:hover { border-color: var(--line); }
59 button.mute { width: 36px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
60 button.mute svg { width: 18px; height: 18px; }
61 button.mute.audible { background: var(--accent-soft); border-color: #b9cde0; color: var(--accent); }
63 #controls { margin-top: 14px; }
64 #energy { min-width: 70px; }
65 #energy-value { min-width: 5.5em; text-align: right; }
66 #ghost-row { margin-top: 10px; min-height: 28px; }
67 #ghost-controls { flex: 1; }
68 #ghost-offset { max-width: 140px; min-width: 80px; }
69 #ghost-sep { width: 100%; }
71 details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
72 summary { cursor: pointer; color: var(--muted); font-size: 13px; list-style: none; }
73 summary::-webkit-details-marker { display: none; }
74 summary::before { content: "▸ "; }
75 details[open] summary::before { content: "▾ "; }
76 details.panel { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
77 details.panel summary { display: flex; align-items: baseline; gap: 10px; }
78 details.panel summary .label { font-size: 12px; color: var(--text); }
79 details.panel[open] summary { margin-bottom: 14px; }
80 #pc-energy { max-width: 360px; }
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-actions { justify-content: flex-end; margin-top: 6px; }
102 #traces canvas, #audio-traces canvas { width: 100%; height: auto; margin-top: 12px; }
104 #audio { margin-top: 16px; }
105 #audio .row + .row { margin-top: 12px; }
106 #audio label { display: flex; align-items: center; gap: 8px; }
107 #audio .grow { flex: 1; min-width: 220px; }
108 #volume { max-width: 110px; }
109 </style>
110 </head>
111 <body>
112 <main>
113 <header>
114 <h1>Double pendulum chaos</h1>
115 </header>
117 <div class="grid">
118 <section class="card">
119 <canvas id="canvas"></canvas>
120 <form id="controls" class="row">
121 <span class="label">Energy</span>
122 <input id="energy" type="range" value="50" min="0" max="120" step="0.1" aria-label="Energy" />
123 <span id="energy-value" class="num">50.0 J</span>
124 <button type="submit" class="primary" title="Start from hanging rest with this energy">Strike</button>
125 <button type="button" id="pause" disabled>Pause</button>
126 </form>
127 <div id="ghost-row" class="row">
128 <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>
129 <span id="ghost-controls" class="row" hidden>
130 <span class="label">Offset</span>
131 <input id="ghost-offset" type="range" min="-12" max="-1" step="1" value="-10" aria-label="Ghost offset (power of ten)" />
132 <span id="ghost-offset-value" class="num"></span>
133 <button id="ghost-reset" type="button" title="Restart the ghost from the pendulum's current state">Reset</button>
134 </span>
135 <span id="ghost-sep" class="num muted"></span>
136 </div>
137 <details>
138 <summary>Parameters</summary>
139 <form id="param-form">
140 <label><span>m<sub>1</sub></span> <input id="p-m1" type="number" step="any" /> <span class="unit">kg</span></label>
141 <label><span>m<sub>2</sub></span> <input id="p-m2" type="number" step="any" /> <span class="unit">kg</span></label>
142 <label><span>l<sub>1</sub></span> <input id="p-l1" type="number" step="any" /> <span class="unit">m</span></label>
143 <label><span>l<sub>2</sub></span> <input id="p-l2" type="number" step="any" /> <span class="unit">m</span></label>
144 <label><span>g</span> <input id="p-g" type="number" step="any" /> <span class="unit">m/s²</span></label>
145 <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>
146 </form>
147 <div id="param-actions" class="row">
148 <button type="submit" form="param-form">Apply</button>
149 <label class="muted">Preset <select id="preset">
150 <option value="">custom</option>
151 <option value="equal">l2 = 1 m</option>
152 <option value="tenth">l2 = 1.5667 m</option>
153 <option value="golden">l2 = 2 m</option>
154 <option value="eightThirds">l2 = 2.1637 m</option>
155 <option value="twelfth">l2 = 3.2476 m</option>
156 <option value="doubleOctave">l2 = 6.886 m</option>
157 </select></label>
158 <span id="param-status"></span>
159 </div>
160 <div id="params"></div>
161 </details>
162 </section>
164 <section class="card">
165 <div class="chips" id="toggles">
166 <label class="chip"><input id="spec-toggle" type="checkbox" /><span>Spectrogram</span></label>
167 </div>
168 <figure id="spec-fig" hidden>
169 <div id="spectrogram"></div>
170 </figure>
171 <div id="traces"></div>
172 </section>
173 </div>
175 <details class="card panel" id="audio">
176 <summary><span class="label">Sound</span></summary>
177 <div class="row">
178 <button id="mute" type="button" class="mute" title="Unmute" aria-label="Unmute"></button>
179 <label><span class="label">Sound of</span> <select id="signal"></select></label>
180 <label><span class="label">Volume</span> <input id="volume" type="range" min="0" max="1" step="0.01" value="0.5" /></label>
181 <span id="audio-chips" class="chips">
182 <label class="chip"><input id="audio-spec-toggle" type="checkbox" checked /><span>Spectrogram</span></label>
183 </span>
184 </div>
185 <div class="row">
186 <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>
187 <span id="pitch-value" class="num"></span>
188 </div>
189 <div class="row"><span id="audio-status" class="muted"></span></div>
190 <figure id="audio-spec-fig">
191 <div id="audio-spectrogram"></div>
192 </figure>
193 <div id="audio-traces"></div>
194 <figure id="scatter-fig" hidden>
195 <div id="scatter"></div>
196 <div class="row scatter-actions"><button id="scatter-clear" type="button">Clear</button></div>
197 </figure>
198 </details>
200 <details class="card panel" id="poincare">
201 <summary><span class="label">Poincaré section</span></summary>
202 <div class="row">
203 <span class="label">Energy</span>
204 <input id="pc-energy" type="range" value="20" min="0" max="120" step="0.1" aria-label="Section energy" />
205 <span id="pc-energy-value" class="num">20.0 J</span>
206 <label class="chip"><input id="pc-lambda" type="checkbox" /><span>Color by λ</span></label>
207 <label class="chip" title="Clicking a point also strikes the pendulum from that exact state, at this energy"><input id="pc-strike" type="checkbox" checked /><span>Click to strike</span></label>
208 <label class="chip" title="The section's energy follows the pendulum's as it decays"><input id="pc-follow" type="checkbox" /><span>Follow</span></label>
209 <span id="pc-status" class="muted"></span>
210 </div>
211 <figure>
212 <div id="pc-plot"></div>
213 </figure>
214 </details>
215 </main>
216 <script type="module" src="/src/main.ts"></script>
217 </body>
218</html>