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