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