/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
413 lines · 18.6 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" />
6 <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><circle cx=%2250%22 cy=%2250%22 r=%2245%22 fill=%22%232a7f62%22/><circle cx=%2235%22 cy=%2238%22 r=%2211%22 fill=%22%23f5d547%22/><circle cx=%2265%22 cy=%2258%22 r=%229%22 fill=%22%23f5d547%22/><circle cx=%2248%22 cy=%2274%22 r=%227%22 fill=%22%23f5d547%22/><circle cx=%2268%22 cy=%2230%22 r=%226%22 fill=%22%23f5d547%22/></svg>" />
7 <title>turing-surface — reaction-diffusion on closed surfaces, live in the browser</title>
8 <style>
9 :root {
10 --bg: #ffffff;
11 --ink: #1f2328;
12 --ink-2: #57606a;
13 --line: #d0d7de;
14 --accent: #0969da;
15 --sphere-bg: #f4f6f8;
16 --tok-com: #6e7781;
17 --tok-str: #0a3069;
18 --tok-num: #0550ae;
19 --tok-kw: #cf222e;
20 --tok-ext: #8250df;
21 color-scheme: light dark;
22 }
23 @media (prefers-color-scheme: dark) {
24 :root {
25 --bg: #14171a;
26 --ink: #e6e9ec;
27 --ink-2: #9aa4af;
28 --line: #333b44;
29 --accent: #58a6ff;
30 --sphere-bg: #14161c;
31 --tok-com: #8b949e;
32 --tok-str: #a5d6ff;
33 --tok-num: #79c0ff;
34 --tok-kw: #ff7b72;
35 --tok-ext: #d2a8ff;
36 }
37 }
38 body {
39 margin: 0;
40 background: var(--bg);
41 color: var(--ink);
42 font: 15px/1.5 system-ui, -apple-system, sans-serif;
43 }
44 main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
45 h1 { font-size: 20px; margin: 0 0 2px; }
46 .sub { color: var(--ink-2); margin: 0 0 12px; font-size: 13px; }
47 .sub a { color: var(--accent); }
48 .controls {
49 display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
50 padding: 6px 0;
51 }
52 /* display:flex above would otherwise override the UA's [hidden] rule */
53 .controls[hidden] { display: none; }
54 .modes {
55 display: flex; flex-wrap: wrap; gap: 8px;
56 padding: 4px 0 10px; margin-bottom: 4px;
57 border-bottom: 1px solid var(--line);
58 }
59 .modes .chip { font-size: 13px; padding: 4px 12px; }
60 .controls label { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
61 select, input[type="number"], button {
62 font: inherit; font-size: 13px;
63 color: var(--ink); background: var(--bg);
64 border: 1px solid var(--line); border-radius: 6px;
65 padding: 4px 8px;
66 }
67 input[type="number"] { width: 6em; }
68 input[type="range"] { width: 8em; vertical-align: middle; accent-color: var(--accent); }
69 button { cursor: pointer; }
70 #geomnote { margin-top: 4px; }
71 button:hover { border-color: var(--accent); }
72 button.primary { border-color: var(--accent); color: var(--accent); font-weight: 600; min-width: 5.5em; }
73 #panels {
74 display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
75 }
76 .panel {
77 flex: 1 1 320px; min-width: 280px;
78 border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
79 display: flex;
80 }
81 .sphere-box { flex: 1; aspect-ratio: 1 / 1; max-height: 70vh; position: relative; }
82 .species-tag {
83 position: absolute; top: 8px; left: 10px; z-index: 2;
84 font-size: 15px; font-weight: 600; color: #fff;
85 background: rgba(0, 0, 0, 0.45);
86 padding: 1px 10px; border-radius: 12px;
87 pointer-events: none;
88 }
89 .colorbar {
90 display: flex; flex-direction: column; align-items: center; justify-content: center;
91 gap: 4px; padding: 8px 4px; background: var(--sphere-bg);
92 width: 52px; flex: none; box-sizing: border-box;
93 }
94 .colorbar canvas { border: 1px solid var(--line); border-radius: 2px; }
95 .colorbar-label { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
96 .stats { margin-top: 10px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
97 .stats b { color: var(--ink); font-weight: 600; }
98 .cli {
99 margin-top: 10px; border: 1px solid var(--line); border-radius: 8px;
100 overflow: hidden;
101 }
102 .cli-head {
103 display: flex; gap: 10px; align-items: center; justify-content: space-between;
104 padding: 6px 10px; font-size: 12px; color: var(--ink-2);
105 background: var(--sphere-bg); border-bottom: 1px solid var(--line);
106 }
107 .cli-head button { padding: 2px 10px; font-size: 12px; }
108 #cmd {
109 display: block; padding: 8px 10px; white-space: pre-wrap;
110 font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
111 color: var(--ink); user-select: all;
112 }
113 #blurb { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
114 #err { color: #b35900; white-space: pre-wrap; font-size: 13px; }
115 .editor {
116 margin-top: 12px; border: 1px solid var(--line); border-radius: 8px;
117 overflow: hidden;
118 }
119 .editor-head {
120 display: flex; gap: 10px; align-items: center; justify-content: space-between;
121 padding: 6px 10px; font-size: 12px; color: var(--ink-2);
122 background: var(--sphere-bg); border-bottom: 1px solid var(--line);
123 }
124 .editor-head button { padding: 2px 10px; font-size: 12px; }
125 /* Source and compiled-op list side by side. The fixed height lives on
126 the row itself, not on either child: a child's own `height` would
127 only be a *hint* stretch fills when unset, and `#compiled` sets its
128 own smaller font, so the same em value would resolve to a shorter
129 box than .editor-code's. Sizing the row instead makes both children
130 stretch to one shared pixel height regardless of either's font. */
131 .editor-body { display: flex; align-items: stretch; height: 34em; }
132 .editor-code { position: relative; flex: 1 1 62%; min-width: 0; }
133 /* The overlay and the textarea must agree on every metric that affects
134 where a character lands. Keep these two rules together. */
135 .editor-code > pre,
136 .editor-code > textarea {
137 margin: 0; padding: 10px 12px; border: 0;
138 box-sizing: border-box; width: 100%; height: 100%;
139 font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
140 tab-size: 2;
141 white-space: pre; overflow-wrap: normal;
142 }
143 #highlight {
144 position: absolute; inset: 0; overflow: hidden;
145 pointer-events: none; background: var(--bg); color: var(--ink);
146 }
147 #source {
148 position: relative; z-index: 1; display: block;
149 resize: none; overflow: auto;
150 background: transparent; color: transparent; caret-color: var(--ink);
151 }
152 #source:focus { outline: none; }
153 /* Transparent text means the selection must be see-through, or selected
154 code would be invisible. */
155 #source::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
156 #compiled {
157 flex: 1 1 38%; min-width: 0; margin: 0; padding: 10px 12px; overflow: auto;
158 border-left: 1px solid var(--line); background: var(--sphere-bg);
159 font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
160 color: var(--ink-2); white-space: pre;
161 }
162 @media (max-width: 860px) {
163 /* Stacked, so each panel goes back to managing its own height rather
164 than sharing the row's fixed one. */
165 .editor-body { flex-direction: column; height: auto; }
166 .editor-code { flex: none; height: 26em; }
167 #compiled { border-left: 0; border-top: 1px solid var(--line); max-height: 12em; }
168 }
169 /* ---- compare mode ------------------------------------------------ */
170 /* The bar's own layout: three chip rows stacked, then the reference
171 picker and the button beside them. */
172 .cmp-axes { display: flex; flex-direction: column; gap: 4px; }
173 .cmp-axis { display: flex; align-items: center; gap: 8px; }
174 .cmp-axis > span:first-child {
175 color: var(--ink-2); font-size: 13px; width: 5.5em; text-align: right;
176 }
177 .chips { display: flex; flex-wrap: wrap; gap: 4px; }
178 .chip {
179 font: inherit; font-size: 12px; padding: 2px 8px;
180 border: 1px solid var(--line); border-radius: 999px;
181 background: var(--bg); color: var(--ink-2); cursor: pointer;
182 }
183 .chip:hover { border-color: var(--accent); }
184 .chip[aria-pressed="true"] {
185 border-color: var(--accent); color: var(--accent);
186 background: color-mix(in srgb, var(--accent) 12%, transparent);
187 font-weight: 600;
188 }
189 /* The panel area becomes a stack of labelled rows. Overrides the flex
190 wrap the single-run view uses. */
191 #panels.compare { flex-direction: column; gap: 8px; }
192 .cmp-row { display: flex; align-items: stretch; gap: 8px; }
193 .cmp-rowlabel {
194 flex: none; width: 13em; padding: 6px 8px;
195 border-left: 4px solid var(--c, var(--line));
196 font-size: 12px; color: var(--ink-2);
197 display: flex; flex-direction: column; justify-content: center; gap: 3px;
198 }
199 .cmp-rowname { color: var(--ink); font-weight: 600; }
200 .cmp-rowstat { font-variant-numeric: tabular-nums; line-height: 1.35; }
201 .cmp-diverged { color: var(--warn-edge); }
202 /* The header row's label cell is a spacer, not a variant — no swatch. */
203 .cmp-head .cmp-rowlabel { border-left-color: transparent; padding: 0 8px; }
204 .cmp-cols { flex: 1; display: flex; gap: 8px; min-width: 0; }
205 .cmp-box {
206 flex: 1 1 0; min-width: 0;
207 border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
208 max-height: 42vh;
209 }
210 .cmp-head { align-items: flex-end; }
211 .cmp-colhead {
212 flex: 1 1 0; min-width: 0;
213 display: flex; align-items: center; gap: 8px;
214 font-size: 12px; color: var(--ink-2);
215 }
216 .cmp-rangebar {
217 flex: 1 1 auto; min-width: 0; height: 8px;
218 border: 1px solid var(--line); border-radius: 2px;
219 }
220 .cmp-rangelab { font-variant-numeric: tabular-nums; white-space: nowrap; }
221 @media (max-width: 860px) {
222 .cmp-row { flex-direction: column; }
223 .cmp-rowlabel { width: auto; flex-direction: row; gap: 10px; }
224 .cmp-head { display: none; }
225 }
226 .tok-com { color: var(--tok-com); }
227 .tok-str { color: var(--tok-str); }
228 .tok-num { color: var(--tok-num); }
229 .tok-kw { color: var(--tok-kw); font-weight: 600; }
230 .tok-ext { color: var(--tok-ext); }
231 </style>
232 </head>
233 <body>
234 <main>
235 <h1>turing-surface</h1>
236 <p class="sub">
237 Reaction-diffusion on closed surfaces, solved live with spherical
238 harmonics on WebGPU via
239 <a href="https://github.com/concept-collection/shtns-webgpu">shtns-webgpu</a>.
240 Both the solver and the shape are the MATLAB below, run in your
241 browser by <a href="https://numbl.org">numbl</a>. Edit either and watch
242 it change. Drag to rotate.
243 </p>
244 <div class="modes" id="modebar">
245 <button type="button" class="chip" id="mode-simulate" aria-pressed="true">Simulate</button>
246 <button type="button" class="chip" id="mode-effort"
247 title="Run several solver settings side by side on one clock">Compare computational effort</button>
248 <button type="button" class="chip" id="mode-vs-sphere" disabled title="Coming soon">Compare against sphere (Coming soon)</button>
249 <button type="button" class="chip" id="mode-vs-upload"
250 title="Check this solver against a saved reference run">
251 Compare against uploaded data</button>
252 <input type="file" id="cmp-file" accept=".h5" hidden>
253 </div>
254 <div class="controls ctrl-group" data-group="surface">
255 <label>reaction-diffusion model
256 <select id="model"></select>
257 </label>
258 <label title="The surface the pattern is solved on. Swapping it does not recompile the solver or restart the run.">geometry
259 <select id="geometry"></select>
260 </label>
261 </div>
262 <div class="ctrl-group" data-group="surface-params">
263 <div class="controls" id="params"></div>
264 <div class="controls" id="geomparams"></div>
265 </div>
266 <div class="controls" id="comparebar" hidden>
267 <div class="cmp-axes">
268 <div class="cmp-axis">
269 <span title="Iterations of the implicit diffusion solve">solve iters</span>
270 <span id="cmp-niter" class="chips"></span>
271 </div>
272 <div class="cmp-axis">
273 <span>lmax</span>
274 <span id="cmp-lmax" class="chips"></span>
275 </div>
276 <div class="cmp-axis">
277 <span title="Timestep, as a divisor of the model's dt. Divisors keep every variant on the same clock exactly.">dt</span>
278 <span id="cmp-dt" class="chips"></span>
279 </div>
280 </div>
281 <label title="The run everything else is measured against">reference
282 <select id="cmp-ref"></select>
283 </label>
284 <span id="cmp-fileinfo" class="stats" hidden></span>
285 <button id="cmp-fileclear" hidden
286 title="Drop the reference file and compare the variants against each other again">×</button>
287 <button id="cmp-start" class="primary">Compile comparison</button>
288 <span id="cmp-count" class="stats"></span>
289 </div>
290 <div class="controls ctrl-group" data-group="solver">
291 <label title="Iterations of the implicit diffusion solve. Changing it recompiles.">solve iters
292 <select id="niter">
293 <option value="0">0</option>
294 <option value="1">1</option>
295 <option value="2">2</option>
296 <option value="4">4</option>
297 <option value="8" selected>8</option>
298 <option value="16">16</option>
299 <option value="32">32</option>
300 <option value="64">64</option>
301 <option value="128">128</option>
302 </select>
303 </label>
304 <label>lmax
305 <select id="lmax">
306 <option value="31">31</option>
307 <option value="63" selected>63</option>
308 <option value="127">127</option>
309 <option value="255">255</option>
310 </select>
311 </label>
312 </div>
313 <div class="controls ctrl-group" data-group="display">
314 <label title="Render on a finer grid. Display only.">display oversampling
315 <select id="oversample">
316 <option value="auto" selected>auto</option>
317 <option value="1">off</option>
318 <option value="2"></option>
319 <option value="4"></option>
320 <option value="8"></option>
321 </select>
322 </label>
323 <label>colormap
324 <select id="colormap"></select>
325 </label>
326 <label title="Blend between the sphere (0) and the surface (1). Display only.">morph
327 <input type="range" id="morph" min="0" max="1" step="0.01" value="1" />
328 </label>
329 <button id="resetview">Reset view</button>
330 </div>
331 <div class="controls ctrl-group" data-group="playback">
332 <button id="runpause" class="primary">Run</button>
333 </div>
334 <div class="controls ctrl-group" data-group="benchmark">
335 <button id="benchmark">Benchmark</button>
336 </div>
337 <div class="controls ctrl-group" data-group="seed">
338 <label title="Wavelength of the smooth random field the initial condition is seeded from (chebfun's randnfun3, restricted to the surface). An absolute length in the surface's own units, as in chebfun — not a fraction of its size — so smaller means finer features to grow from. Nothing caps it but memory and patience — 0.02 takes about 3 s to seed, 0.01 about 25 s — but it is only *useful* down to about 2*pi/lmax (0.1 at lmax 63): below that the field carries more detail than the grid holds, init's analys discards it, and the seed gets weaker rather than finer. Raise lmax to go finer.">seed λ
339 <input id="lam3" type="number" min="0" step="0.05" value="0.5">
340 </label>
341 <button id="reseed">Re-seed</button>
342 </div>
343 <div class="controls ctrl-group" data-group="movie">
344 <button id="movietoggle" title="Export the run as an MP4 movie">Export movie</button>
345 <div class="controls" id="moviebar" hidden>
346 <label title="Simulation-time units per second of video">movie speed
347 <select id="moviespeed">
348 <option value="0.1">0.1×</option>
349 <option value="0.5">0.5×</option>
350 <option value="1"></option>
351 <option value="3"></option>
352 <option value="5"></option>
353 <option value="10" selected>10×</option>
354 <option value="20">20×</option>
355 </select>
356 </label>
357 <label title="Size of each sphere panel in the video, in pixels">resolution
358 <select id="movieres">
359 <option value="480">480</option>
360 <option value="640">640</option>
361 <option value="768" selected>768</option>
362 <option value="1080">1080</option>
363 <option value="1440">1440</option>
364 </select>
365 </label>
366 <label title="Slowly orbit the camera during the movie">
367 <input type="checkbox" id="movierotate" checked /> auto-rotate
368 </label>
369 <button id="movie" title="Replay the run from t = 0 and download an MP4">Export</button>
370 </div>
371 </div>
372 <p id="geomnote" class="stats"></p>
373 <div id="panels"></div>
374 <p class="stats" id="stats"></p>
375 <p class="stats" id="benchresult"></p>
376 <div class="editor">
377 <div class="editor-head">
378 <span>
379 <select id="editor-file" aria-label="file to edit"></select>
380 <span id="editor-title"></span>
381 </span>
382 <span>
383 <button id="recompile" type="button">Recompile</button>
384 <button id="revert" type="button">Revert</button>
385 </span>
386 </div>
387 <div class="editor-body">
388 <div class="editor-code">
389 <pre id="highlight" aria-hidden="true"></pre>
390 <textarea
391 id="source"
392 spellcheck="false"
393 autocomplete="off"
394 autocapitalize="off"
395 aria-label="model source (MATLAB)"
396 ></textarea>
397 </div>
398 <pre id="compiled"></pre>
399 </div>
400 </div>
401 <div class="cli">
402 <div class="cli-head">
403 <span>The same run on the desktop</span>
404 <button id="copycmd" type="button">Copy</button>
405 </div>
406 <code id="cmd"></code>
407 </div>
408 <p id="blurb"></p>
409 <p id="err"></p>
410 </main>
411 <script type="module" src="/src/main.ts"></script>
412 </body>
413</html>
moveopenescclose