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.sound { min-width: 86px; }
61 button.sound.on { background: var(--accent-soft); border-color: #b9cde0; color: var(--accent); }
63 #controls { margin-top: 14px; }
64 #energy-value { min-width: 5.5em; text-align: right; }
65 #ghost-row { margin-top: 10px; min-height: 28px; }
66 #ghost-controls { flex: 1; }
67 #ghost-offset { max-width: 140px; min-width: 80px; }
68 #ghost-sep { width: 100%; }
70 details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
71 summary { cursor: pointer; color: var(--muted); font-size: 13px; list-style: none; }
72 summary::before { content: "▸ "; }
73 details[open] summary::before { content: "▾ "; }
74 #param-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 16px; margin-top: 10px; }
75 #param-form label { display: grid; grid-template-columns: 1.6em 5.5em auto; align-items: center; gap: 6px; font-size: 13px; }
76 #param-form .unit { color: var(--muted); font-size: 12px; }
77 #param-actions { margin-top: 10px; }
78 #param-status { color: #a33; font-size: 12px; }
79 #params { margin-top: 10px; font: 12px/1.6 var(--mono); color: var(--muted); white-space: pre; overflow-x: auto; }
81 .chips { display: flex; flex-wrap: wrap; gap: 6px; }
82 .chip { position: relative; cursor: pointer; user-select: none; }
83 .chip input { position: absolute; opacity: 0; pointer-events: none; }
84 .chip span {
85 display: inline-block; font-size: 12px; padding: 3px 11px; border-radius: 999px;
86 border: 1px solid var(--line); color: var(--muted); background: #fff;
87 }
88 .chip:hover span { border-color: #c9c8c0; }
89 .chip input:checked + span { background: var(--accent-soft); border-color: #b9cde0; color: var(--accent); }
90 .chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
92 figure { margin: 14px 0 0; }
93 figure canvas { width: 100%; height: auto; border-radius: 4px; }
94 figcaption { margin-top: 4px; }
95 #traces canvas { width: 100%; height: auto; margin-top: 12px; }
96 #plots-empty { margin: 14px 0 2px; }
98 #audio { margin-top: 16px; }
99 #audio .row + .row { margin-top: 12px; }
100 #audio label { display: flex; align-items: center; gap: 8px; }
101 #audio .grow { flex: 1; min-width: 220px; }
102 #volume { max-width: 110px; }
103 </style>
104 </head>
105 <body>
106 <main>
107 <header>
108 <h1>Double pendulum</h1>
109 <p class="sub">Raise the energy and listen for where the motion becomes chaotic.</p>
110 </header>
112 <div class="grid">
113 <section class="card">
114 <canvas id="canvas"></canvas>
115 <form id="controls" class="row">
116 <span class="label">Energy</span>
117 <input id="energy" type="range" value="50" min="0" max="120" step="0.1" aria-label="Energy" />
118 <span id="energy-value" class="num">50.0 J</span>
119 <button type="submit" class="primary" title="Start from hanging rest with this energy">Strike</button>
120 <button type="button" id="pause" disabled>Pause</button>
121 </form>
122 <div id="ghost-row" class="row">
123 <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>
124 <span id="ghost-controls" class="row" hidden>
125 <span class="label">Offset</span>
126 <input id="ghost-offset" type="range" min="-12" max="-1" step="1" value="-10" aria-label="Ghost offset (power of ten)" />
127 <span id="ghost-offset-value" class="num"></span>
128 <button id="ghost-reset" type="button" title="Restart the ghost from the pendulum's current state">Reset</button>
129 </span>
130 <span id="ghost-sep" class="num muted"></span>
131 </div>
132 <details>
133 <summary>Parameters</summary>
134 <form id="param-form">
135 <label><span>m<sub>1</sub></span> <input id="p-m1" type="number" step="any" /> <span class="unit">kg</span></label>
136 <label><span>m<sub>2</sub></span> <input id="p-m2" type="number" step="any" /> <span class="unit">kg</span></label>
137 <label><span>l<sub>1</sub></span> <input id="p-l1" type="number" step="any" /> <span class="unit">m</span></label>
138 <label><span>l<sub>2</sub></span> <input id="p-l2" type="number" step="any" /> <span class="unit">m</span></label>
139 <label><span>g</span> <input id="p-g" type="number" step="any" /> <span class="unit">m/s²</span></label>
140 <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>
141 </form>
142 <div id="param-actions" class="row">
143 <button type="submit" form="param-form">Apply</button>
144 <label class="muted">Preset <select id="preset">
145 <option value="">custom</option>
146 <option value="equal">l2 = 1 m</option>
147 <option value="tenth">l2 = 1.5667 m</option>
148 <option value="golden">l2 = 2 m</option>
149 <option value="eightThirds">l2 = 2.1637 m</option>
150 <option value="twelfth">l2 = 3.2476 m</option>
151 <option value="doubleOctave">l2 = 6.886 m</option>
152 </select></label>
153 <span id="param-status"></span>
154 </div>
155 <div id="params"></div>
156 </details>
157 </section>
159 <section class="card">
160 <div class="chips" id="toggles">
161 <label class="chip"><input id="spec-toggle" type="checkbox" /><span>Spectrogram</span></label>
162 </div>
163 <p id="plots-empty" class="muted">Choose what to plot.</p>
164 <figure id="spec-fig" hidden>
165 <div id="spectrogram"></div>
166 <figcaption id="spec-label" class="muted"></figcaption>
167 </figure>
168 <div id="traces"></div>
169 </section>
170 </div>
172 <section class="card" id="audio">
173 <div class="row">
174 <button id="sound" type="button" class="sound" title="With sound on, every Strike plays a note">Sound off</button>
175 <label><span class="label">Sound of</span> <select id="signal"></select></label>
176 <label><span class="label">Volume</span> <input id="volume" type="range" min="0" max="1" step="0.01" value="0.5" /></label>
177 <label class="chip"><input id="audio-spec-toggle" type="checkbox" /><span>Spectrogram</span></label>
178 </div>
179 <div class="row">
180 <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>
181 <span id="pitch-value" class="num"></span>
182 </div>
183 <div class="row"><span id="audio-status" class="muted"></span></div>
184 <figure id="audio-spec-fig" hidden>
185 <div id="audio-spectrogram"></div>
186 <figcaption id="audio-spec-label" class="muted"></figcaption>
187 </figure>
188 </section>
189 </main>
190 <script type="module" src="/src/main.ts"></script>
191 </body>
192</html>