/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
315 lines · 13.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" />
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 --warn-bg: #fff8e5;
22 --warn-line: #e3c37a;
23 --warn-edge: #bf8700;
24 color-scheme: light dark;
25 }
26 @media (prefers-color-scheme: dark) {
27 :root {
28 --bg: #14171a;
29 --ink: #e6e9ec;
30 --ink-2: #9aa4af;
31 --line: #333b44;
32 --accent: #58a6ff;
33 --sphere-bg: #14161c;
34 --tok-com: #8b949e;
35 --tok-str: #a5d6ff;
36 --tok-num: #79c0ff;
37 --tok-kw: #ff7b72;
38 --tok-ext: #d2a8ff;
39 --warn-bg: #2b2410;
40 --warn-line: #6b5518;
41 --warn-edge: #e3b341;
42 }
43 }
44 body {
45 margin: 0;
46 background: var(--bg);
47 color: var(--ink);
48 font: 15px/1.5 system-ui, -apple-system, sans-serif;
49 }
50 main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
51 h1 { font-size: 20px; margin: 0 0 2px; }
52 .sub { color: var(--ink-2); margin: 0 0 12px; font-size: 13px; }
53 .sub a { color: var(--accent); }
54 .controls {
55 display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
56 padding: 6px 0;
57 }
58 /* display:flex above would otherwise override the UA's [hidden] rule */
59 .controls[hidden] { display: none; }
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 .warn {
115 margin: 0 0 14px;
116 padding: 10px 14px;
117 border: 1px solid var(--warn-line);
118 border-left: 5px solid var(--warn-edge);
119 border-radius: 6px;
120 background: var(--warn-bg);
121 color: var(--ink);
122 font-size: 13.5px; line-height: 1.5;
123 }
124 .warn b { color: var(--warn-edge); }
125 #err { color: #b35900; white-space: pre-wrap; font-size: 13px; }
126 .editor {
127 margin-top: 12px; border: 1px solid var(--line); border-radius: 8px;
128 overflow: hidden;
129 }
130 .editor-head {
131 display: flex; gap: 10px; align-items: center; justify-content: space-between;
132 padding: 6px 10px; font-size: 12px; color: var(--ink-2);
133 background: var(--sphere-bg); border-bottom: 1px solid var(--line);
134 }
135 .editor-head button { padding: 2px 10px; font-size: 12px; }
136 /* Source and compiled-op list side by side, so the editor gets the
137 height rather than sharing it with the list below. */
138 .editor-body { display: flex; align-items: stretch; }
139 .editor-code { position: relative; flex: 1 1 62%; min-width: 0; height: 34em; }
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) {
170 .editor-body { flex-direction: column; }
171 .editor-code { flex: none; height: 26em; }
172 #compiled { border-left: 0; border-top: 1px solid var(--line); max-height: 12em; }
173 }
174 .tok-com { color: var(--tok-com); }
175 .tok-str { color: var(--tok-str); }
176 .tok-num { color: var(--tok-num); }
177 .tok-kw { color: var(--tok-kw); font-weight: 600; }
178 .tok-ext { color: var(--tok-ext); }
179 </style>
180 </head>
181 <body>
182 <main>
183 <h1>turing-surface</h1>
184 <p class="warn">
185 <b>⚠ Work in progress: the geometry is drawn, not solved on.</b>
186 The solver still uses the round sphere's Laplace–Beltrami operator, so
187 on other shapes you see the sphere's pattern painted onto that surface.
188 </p>
189 <p class="sub">
190 Reaction-diffusion on closed surfaces, solved live with spherical
191 harmonics on WebGPU via
192 <a href="https://github.com/concept-collection/shtns-webgpu">shtns-webgpu</a>.
193 Both the solver and the shape are the MATLAB below, compiled in your
194 browser by <a href="https://numbl.org">numbl</a>. Edit either and watch
195 it change. Drag to rotate.
196 </p>
197 <div class="controls">
198 <label>preset
199 <select id="model"></select>
200 </label>
201 <label title="The surface. Rendered, but not yet in the operator.">geometry
202 <select id="geometry"></select>
203 </label>
204 <label title="Blend between the sphere (0) and the surface (1). Display only.">morph
205 <input type="range" id="morph" min="0" max="1" step="0.01" value="1" />
206 </label>
207 <label title="Iterations of the implicit diffusion solve. Changing it recompiles.">solve iters
208 <select id="niter">
209 <option value="0">0</option>
210 <option value="1" selected>1</option>
211 <option value="2">2</option>
212 <option value="4">4</option>
213 <option value="8">8</option>
214 <option value="16">16</option>
215 <option value="32">32</option>
216 <option value="64">64</option>
217 <option value="128">128</option>
218 </select>
219 </label>
220 <label>lmax
221 <select id="lmax">
222 <option value="31">31</option>
223 <option value="63" selected>63</option>
224 <option value="127">127</option>
225 <option value="255">255</option>
226 </select>
227 </label>
228 <label title="Render on a finer grid. Display only.">display oversampling
229 <select id="oversample">
230 <option value="auto" selected>auto</option>
231 <option value="1">off</option>
232 <option value="2"></option>
233 <option value="4"></option>
234 <option value="8"></option>
235 </select>
236 </label>
237 <label>colormap
238 <select id="colormap"></select>
239 </label>
240 <button id="runpause" class="primary">Run</button>
241 <button id="benchmark">Benchmark</button>
242 <button id="reseed">Re-seed</button>
243 <button id="resetview">Reset view</button>
244 <button id="movietoggle" title="Export the run as an MP4 movie">Export movie</button>
245 </div>
246 <div class="controls" id="moviebar" hidden>
247 <label title="Simulation-time units per second of video">movie speed
248 <select id="moviespeed">
249 <option value="0.1">0.1×</option>
250 <option value="0.5">0.5×</option>
251 <option value="1"></option>
252 <option value="3"></option>
253 <option value="5"></option>
254 <option value="10" selected>10×</option>
255 <option value="20">20×</option>
256 </select>
257 </label>
258 <label title="Size of each sphere panel in the video, in pixels">resolution
259 <select id="movieres">
260 <option value="480">480</option>
261 <option value="640">640</option>
262 <option value="768" selected>768</option>
263 <option value="1080">1080</option>
264 <option value="1440">1440</option>
265 </select>
266 </label>
267 <label title="Slowly orbit the camera during the movie">
268 <input type="checkbox" id="movierotate" checked /> auto-rotate
269 </label>
270 <button id="movie" title="Replay the run from t = 0 and download an MP4">Export</button>
271 </div>
272 <div class="controls" id="params"></div>
273 <div class="controls" id="geomparams"></div>
274 <p id="geomnote" class="stats"></p>
275 <div id="panels"></div>
276 <p class="stats" id="stats"></p>
277 <p class="stats" id="benchresult"></p>
278 <div class="editor">
279 <div class="editor-head">
280 <span>
281 <select id="editor-file" aria-label="file to edit"></select>
282 <span id="editor-title"></span>
283 </span>
284 <span>
285 <button id="recompile" type="button">Recompile</button>
286 <button id="revert" type="button">Revert</button>
287 </span>
288 </div>
289 <div class="editor-body">
290 <div class="editor-code">
291 <pre id="highlight" aria-hidden="true"></pre>
292 <textarea
293 id="source"
294 spellcheck="false"
295 autocomplete="off"
296 autocapitalize="off"
297 aria-label="model source (MATLAB)"
298 ></textarea>
299 </div>
300 <pre id="compiled"></pre>
301 </div>
302 </div>
303 <div class="cli">
304 <div class="cli-head">
305 <span>The same run on the desktop</span>
306 <button id="copycmd" type="button">Copy</button>
307 </div>
308 <code id="cmd"></code>
309 </div>
310 <p id="blurb"></p>
311 <p id="err"></p>
312 </main>
313 <script type="module" src="/src/main.ts"></script>
314 </body>
315</html>
moveopenescclose