/ concept-collection / turing-surface
concept-collection / turing-surface
422 lines · 18.6 KBCodeBlameHistory
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 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; }
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; }
2bb4f78Add short descriptions for each modeOwen Melia 60 .mode-desc {
61 color: var(--ink); margin: 0 0 12px; font-size: 13.5px;
62 padding: 10px 14px; border-radius: 6px;
63 border-left: 3px solid var(--accent);
64 background: color-mix(in srgb, var(--accent) 10%, var(--bg));
65 }
66 .mode-desc:empty { display: none; }
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 67 .controls label { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
68 select, input[type="number"], button {
69 font: inherit; font-size: 13px;
70 color: var(--ink); background: var(--bg);
71 border: 1px solid var(--line); border-radius: 6px;
72 padding: 4px 8px;
73 }
74 input[type="number"] { width: 6em; }
75 input[type="range"] { width: 8em; vertical-align: middle; accent-color: var(--accent); }
76 button { cursor: pointer; }
77 #geomnote { margin-top: 4px; }
78 button:hover { border-color: var(--accent); }
79 button.primary { border-color: var(--accent); color: var(--accent); font-weight: 600; min-width: 5.5em; }
80 #panels {
81 display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
82 }
83 .panel {
84 flex: 1 1 320px; min-width: 280px;
85 border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
86 display: flex;
87 }
88 .sphere-box { flex: 1; aspect-ratio: 1 / 1; max-height: 70vh; position: relative; }
89 .species-tag {
90 position: absolute; top: 8px; left: 10px; z-index: 2;
91 font-size: 15px; font-weight: 600; color: #fff;
92 background: rgba(0, 0, 0, 0.45);
93 padding: 1px 10px; border-radius: 12px;
94 pointer-events: none;
95 }
96 .colorbar {
97 display: flex; flex-direction: column; align-items: center; justify-content: center;
98 gap: 4px; padding: 8px 4px; background: var(--sphere-bg);
99 width: 52px; flex: none; box-sizing: border-box;
100 }
101 .colorbar canvas { border: 1px solid var(--line); border-radius: 2px; }
102 .colorbar-label { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
103 .stats { margin-top: 10px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
104 .stats b { color: var(--ink); font-weight: 600; }
105 .cli {
106 margin-top: 10px; border: 1px solid var(--line); border-radius: 8px;
107 overflow: hidden;
108 }
109 .cli-head {
110 display: flex; gap: 10px; align-items: center; justify-content: space-between;
111 padding: 6px 10px; font-size: 12px; color: var(--ink-2);
112 background: var(--sphere-bg); border-bottom: 1px solid var(--line);
113 }
114 .cli-head button { padding: 2px 10px; font-size: 12px; }
115 #cmd {
116 display: block; padding: 8px 10px; white-space: pre-wrap;
117 font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
118 color: var(--ink); user-select: all;
119 }
120 #blurb { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
121 #err { color: #b35900; white-space: pre-wrap; font-size: 13px; }
122 .editor {
123 margin-top: 12px; border: 1px solid var(--line); border-radius: 8px;
124 overflow: hidden;
125 }
126 .editor-head {
127 display: flex; gap: 10px; align-items: center; justify-content: space-between;
128 padding: 6px 10px; font-size: 12px; color: var(--ink-2);
129 background: var(--sphere-bg); border-bottom: 1px solid var(--line);
130 }
131 .editor-head button { padding: 2px 10px; font-size: 12px; }
9389d73WIP: First draft at new interface with multiple comparison modesOwen Melia 132 /* Source and compiled-op list side by side. The fixed height lives on
133 the row itself, not on either child: a child's own `height` would
134 only be a *hint* stretch fills when unset, and `#compiled` sets its
135 own smaller font, so the same em value would resolve to a shorter
136 box than .editor-code's. Sizing the row instead makes both children
137 stretch to one shared pixel height regardless of either's font. */
138 .editor-body { display: flex; align-items: stretch; height: 34em; }
139 .editor-code { position: relative; flex: 1 1 62%; min-width: 0; }
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 140 /* The overlay and the textarea must agree on every metric that affects
141 where a character lands. Keep these two rules together. */
142 .editor-code > pre,
143 .editor-code > textarea {
144 margin: 0; padding: 10px 12px; border: 0;
145 box-sizing: border-box; width: 100%; height: 100%;
146 font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
147 tab-size: 2;
148 white-space: pre; overflow-wrap: normal;
149 }
150 #highlight {
151 position: absolute; inset: 0; overflow: hidden;
152 pointer-events: none; background: var(--bg); color: var(--ink);
153 }
154 #source {
155 position: relative; z-index: 1; display: block;
156 resize: none; overflow: auto;
157 background: transparent; color: transparent; caret-color: var(--ink);
158 }
159 #source:focus { outline: none; }
160 /* Transparent text means the selection must be see-through, or selected
161 code would be invisible. */
162 #source::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
163 #compiled {
164 flex: 1 1 38%; min-width: 0; margin: 0; padding: 10px 12px; overflow: auto;
165 border-left: 1px solid var(--line); background: var(--sphere-bg);
166 font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
167 color: var(--ink-2); white-space: pre;
168 }
169 @media (max-width: 860px) {
9389d73WIP: First draft at new interface with multiple comparison modesOwen Melia 170 /* Stacked, so each panel goes back to managing its own height rather
171 than sharing the row's fixed one. */
172 .editor-body { flex-direction: column; height: auto; }
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 173 .editor-code { flex: none; height: 26em; }
174 #compiled { border-left: 0; border-top: 1px solid var(--line); max-height: 12em; }
175 }
f467ffaCompare several solver settings side by side, on one clockJeremy Magland 176 /* ---- compare mode ------------------------------------------------ */
177 /* The bar's own layout: three chip rows stacked, then the reference
178 picker and the button beside them. */
179 .cmp-axes { display: flex; flex-direction: column; gap: 4px; }
180 .cmp-axis { display: flex; align-items: center; gap: 8px; }
181 .cmp-axis > span:first-child {
182 color: var(--ink-2); font-size: 13px; width: 5.5em; text-align: right;
183 }
184 .chips { display: flex; flex-wrap: wrap; gap: 4px; }
185 .chip {
186 font: inherit; font-size: 12px; padding: 2px 8px;
187 border: 1px solid var(--line); border-radius: 999px;
188 background: var(--bg); color: var(--ink-2); cursor: pointer;
189 }
190 .chip:hover { border-color: var(--accent); }
191 .chip[aria-pressed="true"] {
192 border-color: var(--accent); color: var(--accent);
193 background: color-mix(in srgb, var(--accent) 12%, transparent);
194 font-weight: 600;
195 }
196 /* The panel area becomes a stack of labelled rows. Overrides the flex
197 wrap the single-run view uses. */
198 #panels.compare { flex-direction: column; gap: 8px; }
199 .cmp-row { display: flex; align-items: stretch; gap: 8px; }
200 .cmp-rowlabel {
201 flex: none; width: 13em; padding: 6px 8px;
202 border-left: 4px solid var(--c, var(--line));
203 font-size: 12px; color: var(--ink-2);
204 display: flex; flex-direction: column; justify-content: center; gap: 3px;
205 }
206 .cmp-rowname { color: var(--ink); font-weight: 600; }
207 .cmp-rowstat { font-variant-numeric: tabular-nums; line-height: 1.35; }
208 .cmp-diverged { color: var(--warn-edge); }
209 /* The header row's label cell is a spacer, not a variant — no swatch. */
210 .cmp-head .cmp-rowlabel { border-left-color: transparent; padding: 0 8px; }
211 .cmp-cols { flex: 1; display: flex; gap: 8px; min-width: 0; }
212 .cmp-box {
213 flex: 1 1 0; min-width: 0;
214 border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
215 max-height: 42vh;
216 }
217 .cmp-head { align-items: flex-end; }
218 .cmp-colhead {
219 flex: 1 1 0; min-width: 0;
220 display: flex; align-items: center; gap: 8px;
221 font-size: 12px; color: var(--ink-2);
222 }
223 .cmp-rangebar {
224 flex: 1 1 auto; min-width: 0; height: 8px;
225 border: 1px solid var(--line); border-radius: 2px;
226 }
227 .cmp-rangelab { font-variant-numeric: tabular-nums; white-space: nowrap; }
228 @media (max-width: 860px) {
229 .cmp-row { flex-direction: column; }
230 .cmp-rowlabel { width: auto; flex-direction: row; gap: 10px; }
231 .cmp-head { display: none; }
232 }
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 233 .tok-com { color: var(--tok-com); }
234 .tok-str { color: var(--tok-str); }
235 .tok-num { color: var(--tok-num); }
236 .tok-kw { color: var(--tok-kw); font-weight: 600; }
237 .tok-ext { color: var(--tok-ext); }
238 </style>
239 </head>
240 <body>
241 <main>
242 <h1>turing-surface</h1>
243 <p class="sub">
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 244 Reaction-diffusion on closed surfaces, solved live with spherical
245 harmonics on WebGPU via
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 246 <a href="https://github.com/concept-collection/shtns-webgpu">shtns-webgpu</a>.
f132fe4Drop the work-in-progress bannerDan Fortunato 247 Both the solver and the shape are the MATLAB below, run in your
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 248 browser by <a href="https://numbl.org">numbl</a>. Edit either and watch
249 it change. Drag to rotate.
9389d73WIP: First draft at new interface with multiple comparison modesOwen Melia 251 <div class="modes" id="modebar">
252 <button type="button" class="chip" id="mode-simulate" aria-pressed="true">Simulate</button>
253 <button type="button" class="chip" id="mode-effort"
254 title="Run several solver settings side by side on one clock">Compare computational effort</button>
c8e230aFixing some bugs in the UIOwen Melia 255 <button type="button" class="chip" id="mode-vs-sphere" disabled title="Coming soon">Compare against sphere (Coming soon)</button>
9389d73WIP: First draft at new interface with multiple comparison modesOwen Melia 256 <button type="button" class="chip" id="mode-vs-upload"
c8e230aFixing some bugs in the UIOwen Melia 257 title="Check this solver against a saved reference run">
9389d73WIP: First draft at new interface with multiple comparison modesOwen Melia 258 Compare against uploaded data</button>
259 <input type="file" id="cmp-file" accept=".h5" hidden>
260 </div>
2bb4f78Add short descriptions for each modeOwen Melia 261 <p class="mode-desc" id="mode-desc"></p>
a158c73Update ids in index.html for easier refactorOwen Melia 262 <div class="controls ctrl-group" data-group="surface">
c8e230aFixing some bugs in the UIOwen Melia 263 <label>reaction-diffusion model
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 264 <select id="model"></select>
265 </label>
f132fe4Drop the work-in-progress bannerDan Fortunato 266 <label title="The surface the pattern is solved on. Swapping it does not recompile the solver or restart the run.">geometry
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 267 <select id="geometry"></select>
268 </label>
270 <div class="ctrl-group" data-group="surface-params">
271 <div class="controls" id="params"></div>
272 <div class="controls" id="geomparams"></div>
273 </div>
274 <div class="controls" id="comparebar" hidden>
275 <div class="cmp-axes">
276 <div class="cmp-axis">
277 <span title="Iterations of the implicit diffusion solve">solve iters</span>
278 <span id="cmp-niter" class="chips"></span>
279 </div>
280 <div class="cmp-axis">
281 <span>lmax</span>
282 <span id="cmp-lmax" class="chips"></span>
283 </div>
284 <div class="cmp-axis">
285 <span title="Timestep, as a divisor of the model's dt. Divisors keep every variant on the same clock exactly.">dt</span>
286 <span id="cmp-dt" class="chips"></span>
287 </div>
288 </div>
289 <label title="The run everything else is measured against">reference
290 <select id="cmp-ref"></select>
a158c73Update ids in index.html for easier refactorOwen Melia 292 <span id="cmp-fileinfo" class="stats" hidden></span>
293 <button id="cmp-fileclear" hidden
294 title="Drop the reference file and compare the variants against each other again">×</button>
c8e230aFixing some bugs in the UIOwen Melia 295 <button id="cmp-start" class="primary">Compile comparison</button>
a158c73Update ids in index.html for easier refactorOwen Melia 296 <span id="cmp-count" class="stats"></span>
297 </div>
298 <div class="controls ctrl-group" data-group="solver">
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 299 <label title="Iterations of the implicit diffusion solve. Changing it recompiles.">solve iters
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 300 <select id="niter">
301 <option value="0">0</option>
f467ffaCompare several solver settings side by side, on one clockJeremy Magland 302 <option value="1">1</option>
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 303 <option value="2">2</option>
304 <option value="4">4</option>
f467ffaCompare several solver settings side by side, on one clockJeremy Magland 305 <option value="8" selected>8</option>
067895eadditional options for niterJeremy Magland 306 <option value="16">16</option>
307 <option value="32">32</option>
308 <option value="64">64</option>
309 <option value="128">128</option>
311 </label>
312 <label>lmax
313 <select id="lmax">
314 <option value="31">31</option>
315 <option value="63" selected>63</option>
316 <option value="127">127</option>
317 <option value="255">255</option>
318 </select>
319 </label>
321 <div class="controls ctrl-group" data-group="display">
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 322 <label title="Render on a finer grid. Display only.">display oversampling
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 323 <select id="oversample">
324 <option value="auto" selected>auto</option>
325 <option value="1">off</option>
326 <option value="2"></option>
327 <option value="4"></option>
328 <option value="8"></option>
329 </select>
330 </label>
331 <label>colormap
332 <select id="colormap"></select>
333 </label>
a158c73Update ids in index.html for easier refactorOwen Melia 334 <label title="Blend between the sphere (0) and the surface (1). Display only.">morph
335 <input type="range" id="morph" min="0" max="1" step="0.01" value="1" />
336 </label>
337 <button id="resetview">Reset view</button>
338 </div>
339 <div class="controls ctrl-group" data-group="playback">
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 340 <button id="runpause" class="primary">Run</button>
ca37955Adding a way to reset simulation from same random IC.Owen Melia 341 <button id="restart" title="Rewind to the initial condition this run started from, without drawing a new one">Restart</button>
343 <div class="controls ctrl-group" data-group="benchmark">
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 344 <button id="benchmark">Benchmark</button>
346 <div class="controls ctrl-group" data-group="seed">
ca37955Adding a way to reset simulation from same random IC.Owen Melia 347 <label title="Wavelength of the smooth random field generating the initial condition">Initial condition wavelength λ
0ae15cfSeed runs from smooth random fields, and add the blob geometryDan Fortunato 348 <input id="lam3" type="number" min="0" step="0.05" value="0.5">
349 </label>
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 350 <button id="reseed">Re-seed</button>
a158c73Update ids in index.html for easier refactorOwen Melia 352 <div class="controls ctrl-group" data-group="movie">
353 <button id="movietoggle" title="Export the run as an MP4 movie">Export movie</button>
354 <div class="controls" id="moviebar" hidden>
355 <label title="Simulation-time units per second of video">movie speed
356 <select id="moviespeed">
357 <option value="0.1">0.1×</option>
358 <option value="0.5">0.5×</option>
359 <option value="1"></option>
360 <option value="3"></option>
361 <option value="5"></option>
362 <option value="10" selected>10×</option>
363 <option value="20">20×</option>
364 </select>
365 </label>
366 <label title="Size of each sphere panel in the video, in pixels">resolution
367 <select id="movieres">
368 <option value="480">480</option>
369 <option value="640">640</option>
370 <option value="768" selected>768</option>
371 <option value="1080">1080</option>
372 <option value="1440">1440</option>
373 </select>
374 </label>
375 <label title="Slowly orbit the camera during the movie">
376 <input type="checkbox" id="movierotate" checked /> auto-rotate
377 </label>
378 <button id="movie" title="Replay the run from t = 0 and download an MP4">Export</button>
381 <p id="geomnote" class="stats"></p>
382 <div id="panels"></div>
383 <p class="stats" id="stats"></p>
384 <p class="stats" id="benchresult"></p>
385 <div class="editor">
386 <div class="editor-head">
387 <span>
388 <select id="editor-file" aria-label="file to edit"></select>
389 <span id="editor-title"></span>
390 </span>
391 <span>
392 <button id="recompile" type="button">Recompile</button>
393 <button id="revert" type="button">Revert</button>
394 </span>
395 </div>
396 <div class="editor-body">
397 <div class="editor-code">
398 <pre id="highlight" aria-hidden="true"></pre>
399 <textarea
400 id="source"
401 spellcheck="false"
402 autocomplete="off"
403 autocapitalize="off"
404 aria-label="model source (MATLAB)"
405 ></textarea>
406 </div>
407 <pre id="compiled"></pre>
408 </div>
409 </div>
410 <div class="cli">
411 <div class="cli-head">
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 412 <span>The same run on the desktop</span>
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 413 <button id="copycmd" type="button">Copy</button>
414 </div>
415 <code id="cmd"></code>
416 </div>
417 <p id="blurb"></p>
418 <p id="err"></p>
419 </main>
420 <script type="module" src="/src/main.ts"></script>
421 </body>
422</html>