motion-library 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +37 -2
- package/anims/basics/anticipation.js +56 -0
- package/anims/basics/card-flip.js +39 -0
- package/anims/basics/easing-race.js +57 -0
- package/anims/basics/fade-scale.js +44 -0
- package/anims/basics/stagger-grid.js +43 -0
- package/anims/chrome/black-hole.js +81 -0
- package/anims/chrome/cloth-reveal.js +156 -0
- package/anims/chrome/dna-helix.js +52 -0
- package/anims/chrome/dust-bust.js +109 -0
- package/anims/chrome/extruded-type.js +64 -0
- package/anims/chrome/fractal-tree.js +75 -0
- package/anims/chrome/gem.js +111 -0
- package/anims/chrome/geode.js +102 -0
- package/anims/chrome/glass-lens.js +73 -0
- package/anims/chrome/glass-prism.js +95 -0
- package/anims/chrome/gyroid.js +69 -0
- package/anims/chrome/holo-card.js +52 -0
- package/anims/chrome/infinite-tunnel.js +81 -0
- package/anims/chrome/inflated-type.js +141 -0
- package/anims/chrome/isometric-city.js +97 -0
- package/anims/chrome/jelly-cube.js +329 -0
- package/anims/chrome/klein-bottle.js +80 -0
- package/anims/chrome/liquid-metal.js +94 -0
- package/anims/chrome/low-poly-planet.js +163 -0
- package/anims/chrome/mandelbulb.js +79 -0
- package/anims/chrome/melting-logo.js +126 -0
- package/anims/chrome/menger-sponge.js +79 -0
- package/anims/chrome/neon-geodesic.js +149 -0
- package/anims/chrome/paper-fold.js +135 -0
- package/anims/chrome/path-spheres.js +112 -0
- package/anims/chrome/point-globe.js +81 -0
- package/anims/chrome/portal.js +105 -0
- package/anims/chrome/rubiks-cube.js +74 -0
- package/anims/chrome/sdf-morph.js +129 -0
- package/anims/chrome/shatter.js +120 -0
- package/anims/chrome/soap-bubble.js +86 -0
- package/anims/chrome/terrain-flyover.js +78 -0
- package/anims/chrome/tesseract.js +148 -0
- package/anims/chrome/torus-knot.js +89 -0
- package/anims/chrome/volumetric-clouds.js +70 -0
- package/anims/flow/bio-shore.js +140 -0
- package/anims/flow/calligraphy.js +116 -0
- package/anims/flow/chladni.js +152 -0
- package/anims/flow/cloud-chamber.js +101 -0
- package/anims/flow/confetti.js +46 -0
- package/anims/flow/curl-flow.js +52 -0
- package/anims/flow/dandelion.js +80 -0
- package/anims/flow/dla-crystal.js +57 -0
- package/anims/flow/drone-show.js +357 -0
- package/anims/flow/embers.js +63 -0
- package/anims/flow/firefly-sync.js +107 -0
- package/anims/flow/galaxy.js +69 -0
- package/anims/flow/galton-board.js +155 -0
- package/anims/flow/gpu-particles.js +73 -0
- package/anims/flow/harmonograph.js +61 -0
- package/anims/flow/holi.js +153 -0
- package/anims/flow/iron-filings.js +112 -0
- package/anims/flow/lightning.js +72 -0
- package/anims/flow/murmuration.js +105 -0
- package/anims/flow/orbitals.js +195 -0
- package/anims/flow/particle-life.js +87 -0
- package/anims/flow/physarum.js +171 -0
- package/anims/flow/pin-art.js +181 -0
- package/anims/flow/rainbow.js +127 -0
- package/anims/flow/roche-limit.js +161 -0
- package/anims/flow/sand-mandala.js +121 -0
- package/anims/flow/scramble-crossing.js +152 -0
- package/anims/flow/snowfall.js +84 -0
- package/anims/flow/sparks.js +71 -0
- package/anims/flow/spider-web.js +123 -0
- package/anims/flow/starry-night.js +121 -0
- package/anims/flow/states-of-matter.js +113 -0
- package/anims/flow/strange-attractor.js +54 -0
- package/anims/flow/wheat-field.js +186 -0
- package/anims/flow/wind-tunnel.js +227 -0
- package/anims/fluid/bubbles.js +152 -0
- package/anims/fluid/caustics.js +45 -0
- package/anims/fluid/dripping-text.js +53 -0
- package/anims/fluid/ferrofluid.js +56 -0
- package/anims/fluid/fire-smoke.js +83 -0
- package/anims/fluid/honey-drip.js +167 -0
- package/anims/fluid/ink-drop.js +50 -0
- package/anims/fluid/ink-fluid.js +125 -0
- package/anims/fluid/lava-lamp.js +56 -0
- package/anims/fluid/liquid-distort.js +64 -0
- package/anims/fluid/liquid-glass-fill.js +53 -0
- package/anims/fluid/marbling.js +53 -0
- package/anims/fluid/mercury.js +177 -0
- package/anims/fluid/ocean-waves.js +50 -0
- package/anims/fluid/paint-swirl.js +153 -0
- package/anims/fluid/raindrops-glass.js +60 -0
- package/anims/fluid/ripples.js +57 -0
- package/anims/fluid/sph-water.js +75 -0
- package/anims/fluid/underwater.js +55 -0
- package/anims/fluid/water-surface-3d.js +98 -0
- package/anims/hover/cursor-trail.js +37 -0
- package/anims/hover/magnetic.js +41 -0
- package/anims/hover/ripple.js +31 -0
- package/anims/hover/spotlight.js +31 -0
- package/anims/hover/tilt.js +36 -0
- package/anims/micro/arc-spinner.js +22 -0
- package/anims/micro/like-burst.js +42 -0
- package/anims/micro/skeleton.js +36 -0
- package/anims/micro/submit-success.js +45 -0
- package/anims/micro/toggle.js +35 -0
- package/anims/morph/gooey.js +36 -0
- package/anims/morph/icon-morph.js +45 -0
- package/anims/morph/line-draw.js +34 -0
- package/anims/morph/liquid-button.js +53 -0
- package/anims/morph/shape-morph.js +61 -0
- package/anims/registry-more.js +327 -0
- package/anims/registry.js +294 -0
- package/anims/scroll/parallax.js +50 -0
- package/anims/scroll/pinned-track.js +40 -0
- package/anims/scroll/scrub-reveal.js +34 -0
- package/anims/scroll/velocity-skew.js +38 -0
- package/anims/scroll/zoom-through.js +41 -0
- package/anims/shaders/aurora.js +47 -0
- package/anims/shaders/dither.js +69 -0
- package/anims/shaders/domain-warp.js +52 -0
- package/anims/shaders/guilloche.js +42 -0
- package/anims/shaders/kaleidoscope.js +64 -0
- package/anims/shaders/reaction-diffusion.js +85 -0
- package/anims/shaders/rgb-glitch.js +56 -0
- package/anims/shaders/truchet.js +57 -0
- package/anims/shaders/voronoi.js +50 -0
- package/anims/springs/ball-collisions.js +47 -0
- package/anims/springs/pendulum-wave.js +35 -0
- package/anims/springs/rubber-band.js +50 -0
- package/anims/springs/squash-bounce.js +50 -0
- package/anims/springs/verlet-rope.js +46 -0
- package/anims/text/letter-rise.js +40 -0
- package/anims/text/line-mask.js +26 -0
- package/anims/text/scramble.js +32 -0
- package/anims/text/typewriter.js +35 -0
- package/anims/text/vf-wave.js +26 -0
- package/anims/transitions/circle-reveal.js +42 -0
- package/anims/transitions/push-slide.js +40 -0
- package/anims/transitions/shared-expand.js +43 -0
- package/anims/transitions/staircase-wipe.js +41 -0
- package/anims/transitions/view-transition.js +43 -0
- package/bin.mjs +155 -0
- package/js/code.js +122 -0
- package/package.json +10 -4
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// States of matter: 950 atoms and one force law (Lennard-Jones: strong repulsion up close, gentle attraction a
|
|
2
|
+
// little further out). A thermostat slowly lowers the temperature. Hot, the atoms are a gas bouncing round the box;
|
|
3
|
+
// cooler, they stick in droplets that rain into a pool; colder still, the pool freezes into a hexagonal crystal with
|
|
4
|
+
// grain boundaries where crystals that started in different places meet. Then it heats up and melts again. Atoms are
|
|
5
|
+
// coloured by speed (that is temperature), and bonds are drawn between close neighbours, so you see the lattice form.
|
|
6
|
+
const PARAMS = { atoms: 950, gravity: 1, cycle: 1 };
|
|
7
|
+
|
|
8
|
+
export default function (stage) {
|
|
9
|
+
const canvas = document.createElement('canvas');
|
|
10
|
+
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;display:block;background:#06080c';
|
|
11
|
+
stage.append(canvas);
|
|
12
|
+
const ctx = canvas.getContext('2d');
|
|
13
|
+
let W = 1, H = 1;
|
|
14
|
+
const N = Math.max(200, Math.round(PARAMS.atoms));
|
|
15
|
+
// reduced units: σ = 1 (atom size), ε = 1, mass 1. The box is 34 σ tall, as wide as the stage allows
|
|
16
|
+
let BX = 56, BY = 34;
|
|
17
|
+
const x = new Float32Array(N), y = new Float32Array(N), vx = new Float32Array(N), vy = new Float32Array(N), fx = new Float32Array(N), fy = new Float32Array(N);
|
|
18
|
+
const nb = new Uint8Array(N);
|
|
19
|
+
function place() {
|
|
20
|
+
const cols = Math.ceil(Math.sqrt(N * BX / BY)), dx = BX / cols, rows = Math.ceil(N / cols), dy = BY / rows;
|
|
21
|
+
for (let i = 0; i < N; i++) { x[i] = ((i % cols) + 0.5) * dx; y[i] = (((i / cols) | 0) + 0.5) * dy; const a = Math.random() * 6.283, s = 1.4; vx[i] = Math.cos(a) * s; vy[i] = Math.sin(a) * s; }
|
|
22
|
+
}
|
|
23
|
+
const resize = () => {
|
|
24
|
+
const d = Math.min(devicePixelRatio, 2); W = stage.clientWidth || 1; H = stage.clientHeight || 1;
|
|
25
|
+
canvas.width = Math.max(1, (W * d) | 0); canvas.height = Math.max(1, (H * d) | 0); ctx.setTransform(d, 0, 0, d, 0, 0);
|
|
26
|
+
const nbx = Math.max(30, Math.min(80, Math.round(34 * W / H))); if (nbx !== BX) { BX = nbx; place(); }
|
|
27
|
+
};
|
|
28
|
+
place();
|
|
29
|
+
const ro = new ResizeObserver(resize); ro.observe(stage); resize();
|
|
30
|
+
|
|
31
|
+
const RC = 2.5, RC2 = RC * RC, CELL = RC;
|
|
32
|
+
let gx = 1, gy = 1, head = new Int32Array(1), next = new Int32Array(N);
|
|
33
|
+
function forces() {
|
|
34
|
+
gx = Math.max(1, Math.floor(BX / CELL)); gy = Math.max(1, Math.floor(BY / CELL));
|
|
35
|
+
if (head.length !== gx * gy) head = new Int32Array(gx * gy);
|
|
36
|
+
head.fill(-1);
|
|
37
|
+
for (let i = 0; i < N; i++) { const c = Math.min(gx - 1, Math.max(0, (x[i] / BX * gx) | 0)) * gy + Math.min(gy - 1, Math.max(0, (y[i] / BY * gy) | 0)); next[i] = head[c]; head[c] = i; }
|
|
38
|
+
fx.fill(0); fy.fill(0); nb.fill(0);
|
|
39
|
+
const G = 0.14 * PARAMS.gravity;
|
|
40
|
+
for (let cxI = 0; cxI < gx; cxI++) for (let cyI = 0; cyI < gy; cyI++) {
|
|
41
|
+
for (let i = head[cxI * gy + cyI]; i >= 0; i = next[i]) {
|
|
42
|
+
for (let ox = 0; ox <= 1; ox++) for (let oy = -1; oy <= 1; oy++) {
|
|
43
|
+
if (ox === 0 && oy < 0) continue; // each neighbouring pair of cells once
|
|
44
|
+
const ncx = cxI + ox, ncy = cyI + oy; if (ncx >= gx || ncy < 0 || ncy >= gy) continue;
|
|
45
|
+
for (let j = head[ncx * gy + ncy]; j >= 0; j = next[j]) {
|
|
46
|
+
if (ox === 0 && oy === 0 && j <= i) continue;
|
|
47
|
+
const dx = x[j] - x[i], dy = y[j] - y[i], r2 = dx * dx + dy * dy;
|
|
48
|
+
if (r2 > RC2 || r2 < 1e-6) continue;
|
|
49
|
+
const ir2 = 1 / Math.max(r2, 0.64), ir6 = ir2 * ir2 * ir2, f = 24 * ir2 * ir6 * (2 * ir6 - 1); // −dU/dr ÷ r for U = 4(r⁻¹² − r⁻⁶)
|
|
50
|
+
fx[i] -= f * dx; fy[i] -= f * dy; fx[j] += f * dx; fy[j] += f * dy;
|
|
51
|
+
if (r2 < 1.44) { nb[i]++; nb[j]++; }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (let i = head[cxI * gy + cyI]; i >= 0; i = next[i]) fy[i] += G; // gravity pulls toward the floor (down the screen)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
forces();
|
|
59
|
+
// the thermostat's target: hot gas → cooling → frozen → reheating, on a loop
|
|
60
|
+
const targetT = s => { const c = 40 / PARAMS.cycle, p = (s % c) / c; return p < 0.12 ? 1.6 : p < 0.55 ? 1.6 - 1.45 * ((p - 0.12) / 0.43) : p < 0.82 ? 0.15 : 0.15 + 1.45 * ((p - 0.82) / 0.18); };
|
|
61
|
+
const stateOf = T => T > 1.0 ? 'gas' : T > 0.43 ? 'liquid' : 'solid';
|
|
62
|
+
|
|
63
|
+
let raf, last = performance.now(), time = 0, Tnow = 1.6;
|
|
64
|
+
function frame(now) {
|
|
65
|
+
const fdt = Math.min(0.05, (now - last) / 1000); last = now; time += fdt;
|
|
66
|
+
const h = 0.005, T0 = targetT(time);
|
|
67
|
+
for (let s = 0; s < 8; s++) { // velocity Verlet
|
|
68
|
+
for (let i = 0; i < N; i++) { vx[i] += 0.5 * h * fx[i]; vy[i] += 0.5 * h * fy[i]; x[i] += h * vx[i]; y[i] += h * vy[i];
|
|
69
|
+
if (x[i] < 0.5) { x[i] = 0.5; vx[i] = Math.abs(vx[i]); } else if (x[i] > BX - 0.5) { x[i] = BX - 0.5; vx[i] = -Math.abs(vx[i]); }
|
|
70
|
+
if (y[i] < 0.5) { y[i] = 0.5; vy[i] = Math.abs(vy[i]); } else if (y[i] > BY - 0.5) { y[i] = BY - 0.5; vy[i] = -Math.abs(vy[i]); } }
|
|
71
|
+
forces();
|
|
72
|
+
let ke = 0;
|
|
73
|
+
for (let i = 0; i < N; i++) { vx[i] += 0.5 * h * fx[i]; vy[i] += 0.5 * h * fy[i]; ke += vx[i] * vx[i] + vy[i] * vy[i]; }
|
|
74
|
+
Tnow = ke / (2 * N); // 2D: kT = ⟨v²⟩ / 2
|
|
75
|
+
const lam = Math.sqrt(1 + (h / 0.4) * (T0 / Math.max(Tnow, 1e-3) - 1)); // Berendsen: nudge every speed toward the target
|
|
76
|
+
for (let i = 0; i < N; i++) { vx[i] *= lam; vy[i] *= lam; }
|
|
77
|
+
}
|
|
78
|
+
// draw: fit the box to the stage
|
|
79
|
+
const sc = Math.min(W / BX, H / BY), ox = (W - BX * sc) / 2, oy = (H - BY * sc) / 2;
|
|
80
|
+
ctx.fillStyle = '#06080c'; ctx.fillRect(0, 0, W, H);
|
|
81
|
+
// bonds between close neighbours: the lattice
|
|
82
|
+
ctx.lineWidth = Math.max(0.7, sc * 0.11); ctx.strokeStyle = 'rgba(150,205,255,.5)'; ctx.beginPath();
|
|
83
|
+
for (let c = 0; c < gx * gy; c++) for (let i = head[c]; i >= 0; i = next[i]) {
|
|
84
|
+
const cxI = (c / gy) | 0, cyI = c % gy;
|
|
85
|
+
for (let ox2 = 0; ox2 <= 1; ox2++) for (let oy2 = -1; oy2 <= 1; oy2++) {
|
|
86
|
+
if (ox2 === 0 && oy2 < 0) continue; const ncx = cxI + ox2, ncy = cyI + oy2; if (ncx >= gx || ncy < 0 || ncy >= gy) continue;
|
|
87
|
+
for (let j = head[ncx * gy + ncy]; j >= 0; j = next[j]) {
|
|
88
|
+
if (ox2 === 0 && oy2 === 0 && j <= i) continue;
|
|
89
|
+
const dx = x[j] - x[i], dy = y[j] - y[i]; if (dx * dx + dy * dy < 1.3) { ctx.moveTo(ox + x[i] * sc, oy + y[i] * sc); ctx.lineTo(ox + x[j] * sc, oy + y[j] * sc); }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
ctx.stroke();
|
|
94
|
+
// atoms: colour by speed; six close neighbours means sitting in a hexagonal crystal, which gets a cool highlight
|
|
95
|
+
const r = Math.max(1.4, sc * 0.25);
|
|
96
|
+
for (let i = 0; i < N; i++) {
|
|
97
|
+
const v = Math.sqrt(vx[i] * vx[i] + vy[i] * vy[i]), k = Math.min(1, v / 2.4);
|
|
98
|
+
const cr = 70 + 185 * k, cg = 150 + 40 * k - 60 * k * k, cb = 255 - 200 * k;
|
|
99
|
+
ctx.fillStyle = nb[i] >= 6 ? `rgb(${Math.min(255, cr * 0.7 + 60)},${Math.min(255, cg + 70)},255)` : `rgb(${cr | 0},${cg | 0},${cb | 0})`;
|
|
100
|
+
ctx.beginPath(); ctx.arc(ox + x[i] * sc, oy + y[i] * sc, r, 0, 6.283); ctx.fill();
|
|
101
|
+
}
|
|
102
|
+
ctx.strokeStyle = 'rgba(200,215,235,.18)'; ctx.lineWidth = 1; ctx.strokeRect(ox, oy, BX * sc, BY * sc);
|
|
103
|
+
// a thermometer
|
|
104
|
+
const tx = ox + 12, ty = oy + 14, th = Math.min(120, BY * sc * 0.4), fill = Math.min(1, Tnow / 1.8);
|
|
105
|
+
ctx.fillStyle = 'rgba(255,255,255,.08)'; ctx.fillRect(tx, ty, 6, th);
|
|
106
|
+
ctx.fillStyle = `rgb(${90 + 165 * fill | 0},${150 - 40 * fill | 0},${255 - 200 * fill | 0})`; ctx.fillRect(tx, ty + th * (1 - fill), 6, th * fill);
|
|
107
|
+
ctx.fillStyle = 'rgba(225,232,245,.75)'; ctx.font = '500 12px ui-monospace, Menlo, monospace'; ctx.textBaseline = 'top';
|
|
108
|
+
ctx.fillText(`T ${Tnow.toFixed(2)} ${stateOf(Tnow)}`, tx + 14, ty);
|
|
109
|
+
raf = requestAnimationFrame(frame);
|
|
110
|
+
}
|
|
111
|
+
raf = requestAnimationFrame(frame);
|
|
112
|
+
return () => { cancelAnimationFrame(raf); ro.disconnect(); canvas.remove(); };
|
|
113
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Strange attractor: thousands of particles follow the Aizawa equations, which never repeat and never escape.
|
|
2
|
+
// Integrated in 3D, projected through a slowly turning camera, with trails from fading instead of clearing.
|
|
3
|
+
const PARAMS = { particles: 2500, speed: 1 };
|
|
4
|
+
|
|
5
|
+
export default function (stage) {
|
|
6
|
+
const canvas = document.createElement('canvas');
|
|
7
|
+
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;display:block';
|
|
8
|
+
stage.append(canvas);
|
|
9
|
+
const ctx = canvas.getContext('2d');
|
|
10
|
+
let W = 0, H = 0;
|
|
11
|
+
const resize = () => { const d = Math.min(devicePixelRatio, 2); W = stage.clientWidth; H = stage.clientHeight; canvas.width = W * d; canvas.height = H * d; ctx.setTransform(d, 0, 0, d, 0, 0); ctx.fillStyle = '#050608'; ctx.fillRect(0, 0, W, H); };
|
|
12
|
+
const ro = new ResizeObserver(resize); ro.observe(stage); resize();
|
|
13
|
+
|
|
14
|
+
// Aizawa system
|
|
15
|
+
const a = 0.95, b = 0.7, c = 0.6, d = 3.5, e = 0.25, f = 0.1;
|
|
16
|
+
const deriv = (x, y, z) => [(z - b) * x - d * y, d * x + (z - b) * y, c + a * z - z * z * z / 3 - (x * x + y * y) * (1 + e * z) + f * z * x * x * x];
|
|
17
|
+
const n = Math.round(PARAMS.particles), P = new Float32Array(n * 3);
|
|
18
|
+
// start anywhere in the volume, then run each particle forward until it has settled onto the attractor
|
|
19
|
+
const settle = (i, steps) => { for (let k = 0; k < steps; k++) { const [dx, dy, dz] = deriv(P[i * 3], P[i * 3 + 1], P[i * 3 + 2]); P[i * 3] += dx * 0.01; P[i * 3 + 1] += dy * 0.01; P[i * 3 + 2] += dz * 0.01; } };
|
|
20
|
+
const seed = i => { P[i * 3] = (Math.random() - 0.5) * 2; P[i * 3 + 1] = (Math.random() - 0.5) * 2; P[i * 3 + 2] = Math.random() * 2 - 0.5; settle(i, 300 + Math.random() * 600); };
|
|
21
|
+
for (let i = 0; i < n; i++) seed(i);
|
|
22
|
+
const prev = new Float32Array(n * 2).fill(NaN);
|
|
23
|
+
let raf;
|
|
24
|
+
function frame(now) {
|
|
25
|
+
const t = now / 1000, yaw = t * 0.25, pitch = 1.15 + Math.sin(t * 0.2) * 0.25;
|
|
26
|
+
const cy = Math.cos(yaw), sy = Math.sin(yaw), cp = Math.cos(pitch), sp = Math.sin(pitch);
|
|
27
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
28
|
+
ctx.fillStyle = 'rgba(5, 6, 8, 0.12)'; ctx.fillRect(0, 0, W, H);
|
|
29
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
30
|
+
const scale = Math.min(W, H) * 0.34, dt = 0.011 * PARAMS.speed;
|
|
31
|
+
ctx.lineWidth = 1;
|
|
32
|
+
for (let i = 0; i < n; i++) {
|
|
33
|
+
let x = P[i * 3], y = P[i * 3 + 1], z = P[i * 3 + 2];
|
|
34
|
+
const [dx, dy, dz] = deriv(x, y, z);
|
|
35
|
+
x += dx * dt; y += dy * dt; z += dz * dt;
|
|
36
|
+
if (!isFinite(x) || Math.abs(x) > 5) { seed(i); prev[i * 2] = NaN; continue; }
|
|
37
|
+
P[i * 3] = x; P[i * 3 + 1] = y; P[i * 3 + 2] = z;
|
|
38
|
+
// rotate: yaw around z (the attractor's axis), then tilt toward the camera
|
|
39
|
+
const rx = x * cy - y * sy, ry = x * sy + y * cy, rz = z - 0.6;
|
|
40
|
+
const py = ry * cp - rz * sp, pz = ry * sp + rz * cp + 3.2;
|
|
41
|
+
const X = W / 2 + (rx / pz) * scale * 3.2, Y = H / 2 + (py / pz) * scale * 3.2;
|
|
42
|
+
const speed = Math.hypot(dx, dy, dz);
|
|
43
|
+
const hue = 190 - Math.min(150, speed * 22); // slow: cyan, fast: warm amber
|
|
44
|
+
if (prev[i * 2] === prev[i * 2]) {
|
|
45
|
+
ctx.strokeStyle = `hsla(${hue}, 90%, ${55 + 12 * (1 - pz / 4)}%, 0.55)`;
|
|
46
|
+
ctx.beginPath(); ctx.moveTo(prev[i * 2], prev[i * 2 + 1]); ctx.lineTo(X, Y); ctx.stroke();
|
|
47
|
+
}
|
|
48
|
+
prev[i * 2] = X; prev[i * 2 + 1] = Y;
|
|
49
|
+
}
|
|
50
|
+
raf = requestAnimationFrame(frame);
|
|
51
|
+
}
|
|
52
|
+
raf = requestAnimationFrame(frame);
|
|
53
|
+
return () => { cancelAnimationFrame(raf); ro.disconnect(); canvas.remove(); };
|
|
54
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Wheat field in wind: about a hundred thousand stalks drawn in one instanced call, each a thin strip that the vertex
|
|
2
|
+
// shader bends. The wind is a noise field sliding across the field, so gusts travel as waves you can follow, and a
|
|
3
|
+
// bent stalk shows more of its ear to the low sun, so every gust rolls across as a wave of brighter gold. The sun sits
|
|
4
|
+
// ahead of the camera: stalks between you and it glow at the rim, the way backlit wheat does. The pointer brushes
|
|
5
|
+
// a path through the stalks.
|
|
6
|
+
const PARAMS = { stalks: 110000, wind: 1, gusts: 1 };
|
|
7
|
+
|
|
8
|
+
export default function (stage) {
|
|
9
|
+
const canvas = document.createElement('canvas');
|
|
10
|
+
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none';
|
|
11
|
+
stage.append(canvas);
|
|
12
|
+
const gl = canvas.getContext('webgl2', { antialias: true });
|
|
13
|
+
if (!gl) { stage.textContent = 'This needs WebGL2.'; return () => canvas.remove(); }
|
|
14
|
+
const N = Math.max(5000, Math.round(PARAMS.stalks));
|
|
15
|
+
|
|
16
|
+
const COMMON = `
|
|
17
|
+
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
|
|
18
|
+
float noise(vec2 p) { vec2 i = floor(p), f = fract(p); f = f * f * (3. - 2. * f); return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + 1.), f.x), f.y); }
|
|
19
|
+
float fbm(vec2 p) { return noise(p) * .55 + noise(p * 2.03 + 7.1) * .3 + noise(p * 4.1 - 3.3) * .15; }
|
|
20
|
+
uniform float T, WIND, GUST; uniform vec3 PTR; // PTR: the pointer on the field (x, z) and its strength
|
|
21
|
+
const vec2 WD = vec2(.94, .34); // the wind's direction
|
|
22
|
+
// the wind at a point: a slow sway everywhere plus gusts, which are blobs of noise sliding downwind
|
|
23
|
+
vec3 wind(vec2 p) {
|
|
24
|
+
float g = smoothstep(.42, .82, fbm(p * .05 - WD * T * .5 * WIND)) * GUST;
|
|
25
|
+
float sway = sin(T * 1.7 * WIND + dot(p, vec2(.8, .35))) * .5 + .5;
|
|
26
|
+
return vec3(WD * (.05 + .32 * g + .05 * sway) * (.4 + .6 * WIND), g);
|
|
27
|
+
}
|
|
28
|
+
uniform vec3 SUN, CAM;
|
|
29
|
+
const vec3 HAZE = vec3(1., .78, .52);
|
|
30
|
+
// gently rolling land: flat where you stand, swelling into low hills further out
|
|
31
|
+
float terr(vec2 p) { return (fbm(p * .012 + 3.1) - .45) * 7. * smoothstep(6., 90., p.y) + p.y * .006; }`;
|
|
32
|
+
|
|
33
|
+
// the sky, the sun and a line of far hills with trees, from each pixel's view ray
|
|
34
|
+
const skyVS = `#version 300 es
|
|
35
|
+
in vec2 p; out vec2 v; void main() { v = p; gl_Position = vec4(p, .9999, 1); }`;
|
|
36
|
+
const skyFS = `#version 300 es
|
|
37
|
+
precision highp float; in vec2 v; out vec4 o; uniform vec3 RT, UP, FW; uniform float F, A;
|
|
38
|
+
${COMMON}
|
|
39
|
+
void main() {
|
|
40
|
+
vec3 d = normalize(FW * F + RT * v.x * A + UP * v.y);
|
|
41
|
+
float el = d.y, az = atan(d.x, d.z);
|
|
42
|
+
vec3 sky = mix(HAZE, vec3(.86, .6, .52), smoothstep(.0, .2, el));
|
|
43
|
+
sky = mix(sky, vec3(.34, .36, .55), smoothstep(.12, .75, el));
|
|
44
|
+
float s = max(dot(d, SUN), 0.);
|
|
45
|
+
sky += vec3(1., .62, .3) * (pow(s, 8.) * .45 + pow(s, 90.) * .6) + vec3(1., .95, .85) * smoothstep(.9994, .9997, s) * 2.;
|
|
46
|
+
float cl = fbm(vec2(az * 4., el * 18.) + vec2(T * .01, 0)) * smoothstep(.02, .12, el) * smoothstep(.45, .15, el); // a few thin streaks of cloud
|
|
47
|
+
sky = mix(sky, mix(vec3(1., .72, .5), vec3(.9, .55, .45), el * 3.), smoothstep(.55, .8, cl) * .5);
|
|
48
|
+
float hill = .012 + .018 * fbm(vec2(az * 5., 1.)) + .01 * fbm(vec2(az * 13., 4.));
|
|
49
|
+
float trees = hill + .011 * pow(smoothstep(.4, .9, fbm(vec2(az * 70., 2.))), .6) * smoothstep(.35, .55, fbm(vec2(az * 6., 9.)));
|
|
50
|
+
vec3 far = mix(vec3(.5, .4, .4), HAZE, .35 + .55 * pow(s, 4.));
|
|
51
|
+
if (el < trees) sky = far * vec3(.72, .7, .74); // the tree line is a little darker than the hills
|
|
52
|
+
if (el < hill) sky = far;
|
|
53
|
+
o = vec4(sky, 1);
|
|
54
|
+
}`;
|
|
55
|
+
// the field's surface beyond the stalks: the same colours and the same gusts, so distance hides where stalks end
|
|
56
|
+
const groundVS = `#version 300 es
|
|
57
|
+
in vec2 p; uniform mat4 M; out vec3 w;
|
|
58
|
+
${COMMON}
|
|
59
|
+
void main() { w = vec3(p.x, terr(p), p.y); gl_Position = M * vec4(w, 1); }`;
|
|
60
|
+
const groundFS = `#version 300 es
|
|
61
|
+
precision highp float; in vec3 w; out vec4 o;
|
|
62
|
+
${COMMON}
|
|
63
|
+
void main() {
|
|
64
|
+
vec3 g = wind(w.xz); float dist = length(w - CAM);
|
|
65
|
+
vec3 v = normalize(w - CAM); float back = pow(max(dot(v, SUN), 0.), 6.);
|
|
66
|
+
// near: soil in the shade between stalks; far: the tops of the ears, all you see at a grazing angle
|
|
67
|
+
vec3 c = mix(vec3(.06, .04, .02), vec3(.46, .32, .13) * (.8 + .4 * fbm(w.xz * .25)), smoothstep(2., 45., dist));
|
|
68
|
+
c *= .72 + .6 * g.z + .9 * back * smoothstep(2., 45., dist);
|
|
69
|
+
o = vec4(mix(c, HAZE * .95, 1. - exp(-dist * .011)), 1);
|
|
70
|
+
}`;
|
|
71
|
+
// one stalk: a strip that faces the camera, thin along the stem and swelling into the ear at the top
|
|
72
|
+
const stalkVS = `#version 300 es
|
|
73
|
+
layout(location = 0) in vec2 m; // m.x: -1 or 1 (side), m.y: 0..1 up the stalk
|
|
74
|
+
layout(location = 1) in vec4 I; // x, z, height, random
|
|
75
|
+
uniform mat4 M; out vec3 col; out vec2 sv; out float fog, back, gust;
|
|
76
|
+
${COMMON}
|
|
77
|
+
void main() {
|
|
78
|
+
vec2 base = I.xy; float L = I.z, r = I.w, v = m.y;
|
|
79
|
+
vec3 wd = wind(base);
|
|
80
|
+
vec2 bend = wd.xy + (vec2(fract(r * 13.7), fract(r * 71.3)) - .5) * .12; // its own lean
|
|
81
|
+
vec2 pd = base - PTR.xy; float pl = length(pd);
|
|
82
|
+
bend += pd / max(pl, .01) * PTR.z * exp(-pl * pl / 1.4) * .9; // the pointer parts the stalks
|
|
83
|
+
float b = length(bend), k = v * v;
|
|
84
|
+
vec3 p = vec3(base.x + bend.x * L * k, terr(base) + L * v * (1. - .28 * b * b * k), base.y + bend.y * L * k);
|
|
85
|
+
vec3 toCam = CAM - p; float dist = length(toCam);
|
|
86
|
+
vec3 side = normalize(cross(vec3(0, 1, 0), toCam));
|
|
87
|
+
float ear = smoothstep(.74, .8, v) * (1. - smoothstep(.88, .93, v)), awn = step(.915, v);
|
|
88
|
+
float wdt = mix(.0022, .0075, ear) * (1. - awn * .55) + dist * .0009; // far stalks widen so they never shimmer below a pixel
|
|
89
|
+
p += side * m.x * wdt;
|
|
90
|
+
gl_Position = M * vec4(p, 1);
|
|
91
|
+
// backlit: we see the shaded side of every stalk, so the body is dark and the light comes through the ears and edges
|
|
92
|
+
float cs = max(dot(normalize(p - CAM), SUN), 0.);
|
|
93
|
+
back = pow(cs, 16.) * 2.2 + pow(cs, 3.) * .3;
|
|
94
|
+
vec3 stem = mix(vec3(.1, .075, .035), vec3(.36, .27, .12), smoothstep(.0, .8, v));
|
|
95
|
+
col = mix(stem, vec3(.4, .27, .11) * (.85 + .3 * fract(r * 5.3)), max(ear, awn));
|
|
96
|
+
sv = vec2(m.x, max(ear, awn * .8)); gust = wd.z; fog = 1. - exp(-dist * .012);
|
|
97
|
+
}`;
|
|
98
|
+
const stalkFS = `#version 300 es
|
|
99
|
+
precision mediump float; in vec3 col; in vec2 sv; in float fog, back, gust; out vec4 o;
|
|
100
|
+
const vec3 HAZE = vec3(1., .78, .52);
|
|
101
|
+
void main() {
|
|
102
|
+
float rim = pow(abs(sv.x), 3.); // edges catch the sun
|
|
103
|
+
vec3 glow = vec3(1., .68, .3) * back * (sv.y * (.75 + .8 * gust) + rim * (.12 + 1.1 * sv.y));
|
|
104
|
+
vec3 c = col * (.62 + .75 * gust * sv.y) + glow + vec3(.05, .045, .05);
|
|
105
|
+
o = vec4(mix(c, HAZE * .95, fog), 1);
|
|
106
|
+
}`;
|
|
107
|
+
|
|
108
|
+
const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s)); return s; };
|
|
109
|
+
const prog = (vs, fs) => {
|
|
110
|
+
const p = gl.createProgram(); gl.attachShader(p, sh(gl.VERTEX_SHADER, vs)); gl.attachShader(p, sh(gl.FRAGMENT_SHADER, fs)); gl.bindAttribLocation(p, 0, 'p'); gl.linkProgram(p);
|
|
111
|
+
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p));
|
|
112
|
+
const u = {}; for (let i = 0, n = gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i < n; i++) { const nm = gl.getActiveUniform(p, i).name; u[nm] = gl.getUniformLocation(p, nm); }
|
|
113
|
+
return { p, u };
|
|
114
|
+
};
|
|
115
|
+
const skyP = prog(skyVS, skyFS), groundP = prog(groundVS, groundFS), stalkP = prog(stalkVS, stalkFS);
|
|
116
|
+
|
|
117
|
+
// geometry
|
|
118
|
+
const vao = (fn) => { const v = gl.createVertexArray(); gl.bindVertexArray(v); fn(); gl.bindVertexArray(null); return v; };
|
|
119
|
+
const buf = (data, loc, size, divisor = 0) => { gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, size, gl.FLOAT, false, 0, 0); gl.vertexAttribDivisor(loc, divisor); };
|
|
120
|
+
const skyV = vao(() => buf(new Float32Array([-1, -1, 3, -1, -1, 3]), 0, 2));
|
|
121
|
+
// the ground: a grid whose rows get further apart with distance and whose width follows the view
|
|
122
|
+
const GR = 140, GC = 90, gv = [], gi = [];
|
|
123
|
+
for (let i = 0; i <= GR; i++) { const z = 0.3 * Math.pow(3000, i / GR); for (let j = 0; j <= GC; j++) gv.push((j / GC * 2 - 1) * Math.max(3, z * 1.4), z); }
|
|
124
|
+
for (let i = 0; i < GR; i++) for (let j = 0; j < GC; j++) { const a = i * (GC + 1) + j, b = a + GC + 1; gi.push(a, b, a + 1, a + 1, b, b + 1); }
|
|
125
|
+
const groundV = vao(() => { buf(new Float32Array(gv), 0, 2); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(gi), gl.STATIC_DRAW); });
|
|
126
|
+
// stem 0–0.76, ear 0.76–0.92, then a thin tuft of awns to the tip
|
|
127
|
+
const STOPS = [0, 0.25, 0.5, 0.7, 0.76, 0.8, 0.85, 0.89, 0.92, 0.96, 1], SEG = STOPS.length - 1, strip = [];
|
|
128
|
+
for (const v of STOPS) strip.push(-1, v, 1, v);
|
|
129
|
+
// stalks are spread so their density on screen is roughly even: more of them near, fewer per square metre far away
|
|
130
|
+
const inst = new Float32Array(N * 4);
|
|
131
|
+
for (let i = 0; i < N; i++) {
|
|
132
|
+
const z = 0.9 * Math.pow(260 / 0.9, Math.random()), x = (Math.random() * 2 - 1) * z * 1.05 + (Math.random() - 0.5) * 0.4;
|
|
133
|
+
inst.set([x, z, 0.85 + Math.random() * 0.3, Math.random()], i * 4);
|
|
134
|
+
}
|
|
135
|
+
const stalkV = vao(() => { buf(new Float32Array(strip), 0, 2); buf(inst, 1, 4, 1); });
|
|
136
|
+
|
|
137
|
+
let W = 1, H = 1;
|
|
138
|
+
const resize = () => { const d = Math.min(devicePixelRatio, 2); W = canvas.width = Math.max(1, (stage.clientWidth * d) | 0); H = canvas.height = Math.max(1, (stage.clientHeight * d) | 0); };
|
|
139
|
+
const ro = new ResizeObserver(resize); ro.observe(stage); resize();
|
|
140
|
+
|
|
141
|
+
// camera: standing in the field, looking out toward the low sun
|
|
142
|
+
const CAM = [0, 1.32, 0], pitch = -0.065, F = 1 / Math.tan(0.42);
|
|
143
|
+
const FW = [0, Math.sin(pitch), Math.cos(pitch)], RT = [1, 0, 0], UP = [0, Math.cos(pitch), -Math.sin(pitch)];
|
|
144
|
+
const SUN = (() => { const a = -0.2, e = 0.045; return [Math.sin(a) * Math.cos(e), Math.sin(e), Math.cos(a) * Math.cos(e)]; })();
|
|
145
|
+
const matrix = () => {
|
|
146
|
+
const A = W / H, n = 0.05, f = 1200, nf = 1 / (n - f);
|
|
147
|
+
const V = [RT[0], UP[0], -FW[0], 0, RT[1], UP[1], -FW[1], 0, RT[2], UP[2], -FW[2], 0,
|
|
148
|
+
-(RT[0] * CAM[0] + RT[1] * CAM[1] + RT[2] * CAM[2]), -(UP[0] * CAM[0] + UP[1] * CAM[1] + UP[2] * CAM[2]), FW[0] * CAM[0] + FW[1] * CAM[1] + FW[2] * CAM[2], 1];
|
|
149
|
+
const P = [F / A, 0, 0, 0, 0, F, 0, 0, 0, 0, (f + n) * nf, -1, 0, 0, 2 * f * n * nf, 0], M = new Float32Array(16);
|
|
150
|
+
for (let c = 0; c < 4; c++) for (let r = 0; r < 4; r++) { let s = 0; for (let k = 0; k < 4; k++) s += P[k * 4 + r] * V[c * 4 + k]; M[c * 4 + r] = s; }
|
|
151
|
+
return M;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// the pointer: cast a ray from the camera to the height of the ears
|
|
155
|
+
const ptr = { x: 0, z: 0, s: 0, on: false };
|
|
156
|
+
const move = e => {
|
|
157
|
+
const r = canvas.getBoundingClientRect(), nx = ((e.clientX - r.left) / r.width) * 2 - 1, ny = 1 - ((e.clientY - r.top) / r.height) * 2, A = r.width / r.height;
|
|
158
|
+
const d = [FW[0] * F + RT[0] * nx * A + UP[0] * ny, FW[1] * F + RT[1] * nx * A + UP[1] * ny, FW[2] * F + RT[2] * nx * A + UP[2] * ny];
|
|
159
|
+
if (d[1] >= -0.001) { ptr.on = false; return; }
|
|
160
|
+
const t = (0.9 - CAM[1]) / d[1]; ptr.x = CAM[0] + d[0] * t; ptr.z = CAM[2] + d[2] * t; ptr.on = true;
|
|
161
|
+
};
|
|
162
|
+
const leave = () => { ptr.on = false; };
|
|
163
|
+
canvas.addEventListener('pointermove', move); canvas.addEventListener('pointerleave', leave);
|
|
164
|
+
|
|
165
|
+
const common = (P, t) => {
|
|
166
|
+
gl.uniform1f(P.u.T, t); gl.uniform1f(P.u.WIND, PARAMS.wind); gl.uniform1f(P.u.GUST, PARAMS.gusts);
|
|
167
|
+
gl.uniform3f(P.u.SUN, ...SUN); gl.uniform3f(P.u.CAM, ...CAM); gl.uniform3f(P.u.PTR, ptr.x, ptr.z, ptr.s);
|
|
168
|
+
};
|
|
169
|
+
let raf, last = performance.now(), t = 0;
|
|
170
|
+
function frame(now) {
|
|
171
|
+
const dt = Math.min(0.05, (now - last) / 1000); last = now; t += dt;
|
|
172
|
+
ptr.s += ((ptr.on ? 1 : 0) - ptr.s) * Math.min(1, dt * 6);
|
|
173
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.viewport(0, 0, W, H);
|
|
174
|
+
gl.enable(gl.DEPTH_TEST); gl.depthFunc(gl.LEQUAL); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
175
|
+
const M = matrix();
|
|
176
|
+
gl.useProgram(skyP.p); common(skyP, t); gl.uniform3f(skyP.u.RT, ...RT); gl.uniform3f(skyP.u.UP, ...UP); gl.uniform3f(skyP.u.FW, ...FW); gl.uniform1f(skyP.u.F, F); gl.uniform1f(skyP.u.A, W / H);
|
|
177
|
+
gl.bindVertexArray(skyV); gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
178
|
+
gl.useProgram(groundP.p); common(groundP, t); gl.uniformMatrix4fv(groundP.u.M, false, M); gl.bindVertexArray(groundV); gl.drawElements(gl.TRIANGLES, gi.length, gl.UNSIGNED_INT, 0);
|
|
179
|
+
gl.useProgram(stalkP.p); common(stalkP, t); gl.uniformMatrix4fv(stalkP.u.M, false, M); gl.bindVertexArray(stalkV);
|
|
180
|
+
gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, (SEG + 1) * 2, N);
|
|
181
|
+
gl.bindVertexArray(null);
|
|
182
|
+
raf = requestAnimationFrame(frame);
|
|
183
|
+
}
|
|
184
|
+
raf = requestAnimationFrame(frame);
|
|
185
|
+
return () => { cancelAnimationFrame(raf); ro.disconnect(); canvas.removeEventListener('pointermove', move); canvas.removeEventListener('pointerleave', leave); gl.getExtension('WEBGL_lose_context')?.loseContext(); canvas.remove(); };
|
|
186
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Wind tunnel: a real fluid solver on the GPU (lattice Boltzmann, D2Q9). Every cell holds nine populations of
|
|
2
|
+
// particles, one per direction; each step they stream to the neighbouring cell and relax toward equilibrium, and
|
|
3
|
+
// out of that comes viscous flow. Past a body the boundary layer peels away and the wake rolls up into a Kármán
|
|
4
|
+
// vortex street: eddies shed alternately from each side. A rake of smoke lines rides the flow as in a real tunnel.
|
|
5
|
+
// The body changes every few seconds (cylinder, wing, plate); drag it to steer the wake.
|
|
6
|
+
const PARAMS = { reynolds: 220, speed: 1, smoke: 15 };
|
|
7
|
+
|
|
8
|
+
export default function (stage) {
|
|
9
|
+
const canvas = document.createElement('canvas');
|
|
10
|
+
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:grab';
|
|
11
|
+
stage.append(canvas);
|
|
12
|
+
const gl = canvas.getContext('webgl2', { antialias: false });
|
|
13
|
+
if (!gl || !gl.getExtension('EXT_color_buffer_float')) { stage.textContent = 'This needs WebGL2 with float render targets.'; return () => canvas.remove(); }
|
|
14
|
+
|
|
15
|
+
let NX = 480, NY = 200; // lattice size: set from the stage's shape below
|
|
16
|
+
const U0 = 0.1; // inflow speed, in cells per step
|
|
17
|
+
const QUAD = `#version 300 es
|
|
18
|
+
in vec2 p; out vec2 uv; void main() { uv = p * .5 + .5; gl_Position = vec4(p, 0, 1); }`;
|
|
19
|
+
const SHAPE = `
|
|
20
|
+
uniform vec4 OB; uniform int SH; // body: centre (cells), size, angle; which shape
|
|
21
|
+
// signed distance (in cells) to the body: cylinder, a NACA 0012 wing at an angle, or a flat plate
|
|
22
|
+
float body(vec2 q) {
|
|
23
|
+
vec2 p = q - OB.xy; float c = cos(OB.w), s = sin(OB.w); p = vec2(c * p.x + s * p.y, -s * p.x + c * p.y);
|
|
24
|
+
float D = OB.z;
|
|
25
|
+
if (SH == 0) return length(p) - D * .5;
|
|
26
|
+
if (SH == 1) {
|
|
27
|
+
float ch = D * 2.6, x = p.x / ch + .35;
|
|
28
|
+
float xc = clamp(x, 0., 1.), yt = .6 * ch * (.2969 * sqrt(xc) - .126 * xc - .3516 * xc * xc + .2843 * xc * xc * xc - .1015 * xc * xc * xc * xc);
|
|
29
|
+
float d = abs(p.y) - yt;
|
|
30
|
+
return x < 0. ? length(vec2(x * ch, p.y)) : x > 1. ? length(vec2((x - 1.) * ch, p.y)) : d;
|
|
31
|
+
}
|
|
32
|
+
vec2 b = abs(p) - vec2(D * .09, D * .62); return length(max(b, 0.)) + min(max(b.x, b.y), 0.);
|
|
33
|
+
}`;
|
|
34
|
+
// one lattice Boltzmann step: pull the populations from the neighbours (bouncing back off the body), relax them
|
|
35
|
+
const stepFS = `#version 300 es
|
|
36
|
+
precision highp float; precision highp int;
|
|
37
|
+
uniform highp sampler2D T0, T1, T2; uniform ivec2 N; uniform float TAU, U; uniform vec2 OV;
|
|
38
|
+
layout(location = 0) out vec4 o0; layout(location = 1) out vec4 o1; layout(location = 2) out vec4 o2;
|
|
39
|
+
${SHAPE}
|
|
40
|
+
const vec2 E[9] = vec2[9](vec2(0, 0), vec2(1, 0), vec2(0, 1), vec2(-1, 0), vec2(0, -1), vec2(1, 1), vec2(-1, 1), vec2(-1, -1), vec2(1, -1));
|
|
41
|
+
const float Wt[9] = float[9](4. / 9., 1. / 9., 1. / 9., 1. / 9., 1. / 9., 1. / 36., 1. / 36., 1. / 36., 1. / 36.);
|
|
42
|
+
const int OPP[9] = int[9](0, 3, 4, 1, 2, 7, 8, 5, 6);
|
|
43
|
+
float pop(ivec2 c, int i) { if (i < 4) return texelFetch(T0, c, 0)[i]; if (i < 8) return texelFetch(T1, c, 0)[i - 4]; return texelFetch(T2, c, 0).x; }
|
|
44
|
+
float feq(int i, float rho, vec2 u) { float eu = dot(E[i], u); return Wt[i] * rho * (1. + 3. * eu + 4.5 * eu * eu - 1.5 * dot(u, u)); }
|
|
45
|
+
void main() {
|
|
46
|
+
ivec2 c = ivec2(gl_FragCoord.xy);
|
|
47
|
+
float f[9]; float rho = 0.; vec2 u = vec2(0);
|
|
48
|
+
if (body(vec2(c)) < 0.) { // inside the body: still fluid at the body's speed
|
|
49
|
+
for (int i = 0; i < 9; i++) f[i] = feq(i, 1., OV);
|
|
50
|
+
o0 = vec4(f[0], f[1], f[2], f[3]); o1 = vec4(f[4], f[5], f[6], f[7]); o2 = vec4(f[8], 1., 0., 0.); return;
|
|
51
|
+
}
|
|
52
|
+
for (int i = 0; i < 9; i++) {
|
|
53
|
+
ivec2 s = c - ivec2(E[i]); s.y = (s.y + N.y) % N.y; s.x = clamp(s.x, 0, N.x - 1);
|
|
54
|
+
f[i] = body(vec2(s)) < 0. ? pop(c, OPP[i]) + 6. * Wt[i] * dot(E[i], OV) : pop(s, i);
|
|
55
|
+
}
|
|
56
|
+
if (c.x == 0) { for (int i = 0; i < 9; i++) f[i] = feq(i, 1., vec2(U, 0)); }
|
|
57
|
+
for (int i = 0; i < 9; i++) { rho += f[i]; u += f[i] * E[i]; }
|
|
58
|
+
u /= rho;
|
|
59
|
+
// Smagorinsky: where the flow shears hard, add a little viscosity, which keeps high speeds stable
|
|
60
|
+
float pxx = 0., pyy = 0., pxy = 0.;
|
|
61
|
+
for (int i = 0; i < 9; i++) { float ne = f[i] - feq(i, rho, u); pxx += E[i].x * E[i].x * ne; pyy += E[i].y * E[i].y * ne; pxy += E[i].x * E[i].y * ne; }
|
|
62
|
+
float Q = sqrt(2. * (pxx * pxx + pyy * pyy + 2. * pxy * pxy));
|
|
63
|
+
float tau = .5 * (TAU + sqrt(TAU * TAU + 18. * .0144 * Q / rho));
|
|
64
|
+
for (int i = 0; i < 9; i++) f[i] += (feq(i, rho, u) - f[i]) / tau;
|
|
65
|
+
o0 = vec4(f[0], f[1], f[2], f[3]); o1 = vec4(f[4], f[5], f[6], f[7]); o2 = vec4(f[8], rho, u);
|
|
66
|
+
}`;
|
|
67
|
+
// smoke: carried backwards along the velocity (semi-Lagrangian), fed in by a rake of nozzles at the inlet
|
|
68
|
+
const smokeFS = `#version 300 es
|
|
69
|
+
precision highp float; in vec2 uv; out vec4 o;
|
|
70
|
+
uniform sampler2D D, HAT; uniform highp sampler2D T2; uniform ivec2 N; uniform float K, LINES, T; uniform int MODE;
|
|
71
|
+
${SHAPE}
|
|
72
|
+
vec2 vel(vec2 p) { // bilinear velocity from the lattice, in cells per step
|
|
73
|
+
p = p - .5; ivec2 i = ivec2(floor(p)); vec2 f = fract(p);
|
|
74
|
+
ivec2 m = N - 1;
|
|
75
|
+
vec2 a = texelFetch(T2, clamp(i, ivec2(0), m), 0).zw, b = texelFetch(T2, clamp(i + ivec2(1, 0), ivec2(0), m), 0).zw;
|
|
76
|
+
vec2 c = texelFetch(T2, clamp(i + ivec2(0, 1), ivec2(0), m), 0).zw, d = texelFetch(T2, clamp(i + ivec2(1, 1), ivec2(0), m), 0).zw;
|
|
77
|
+
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
|
|
78
|
+
}
|
|
79
|
+
void main() {
|
|
80
|
+
vec2 p = uv * vec2(N), dim = vec2(N) * 2.;
|
|
81
|
+
vec2 v = vel(p), back = p - vel(p - v * K * .5) * K; // a midpoint step keeps the curls round
|
|
82
|
+
vec4 s;
|
|
83
|
+
if (MODE == 0) s = texture(D, back / vec2(N)); // predict: plain backward advection
|
|
84
|
+
else {
|
|
85
|
+
// MacCormack: advect the prediction forward again, and the mismatch is the blur it introduced; take half back.
|
|
86
|
+
// Clamping to the neighbourhood it came from stops the correction from overshooting into rings.
|
|
87
|
+
vec2 fwd = p + vel(p + v * K * .5) * K;
|
|
88
|
+
vec4 hat = texture(HAT, uv), tilde = texture(HAT, fwd / vec2(N));
|
|
89
|
+
s = hat + .5 * (texture(D, uv) - tilde);
|
|
90
|
+
vec2 bt = back * 2. - .5, b0 = (floor(bt) + .5) / dim, e = 1. / dim;
|
|
91
|
+
vec4 a = texture(D, b0), b = texture(D, b0 + vec2(e.x, 0)), c = texture(D, b0 + vec2(0, e.y)), d = texture(D, b0 + e);
|
|
92
|
+
s = clamp(s, min(min(a, b), min(c, d)), max(max(a, b), max(c, d))) * .999;
|
|
93
|
+
}
|
|
94
|
+
if (body(p) < 1.) s = vec4(0);
|
|
95
|
+
if (p.x < 2.5) { // the rake: thin coloured jets at even heights
|
|
96
|
+
float k = (uv.y * LINES) - .5, j = floor(k + .5), d = abs(k - j) * float(N.y) / LINES;
|
|
97
|
+
float h = j / max(1., LINES - 1.);
|
|
98
|
+
vec3 c = mix(mix(vec3(.2, .8, 1.), vec3(.95, .95, 1.), smoothstep(0., .5, h)), vec3(1., .5, .2), smoothstep(.5, 1., h));
|
|
99
|
+
s = vec4(c * smoothstep(1.1, .45, d), 1);
|
|
100
|
+
}
|
|
101
|
+
o = s;
|
|
102
|
+
}`;
|
|
103
|
+
const showFS = `#version 300 es
|
|
104
|
+
precision highp float; in vec2 uv; out vec4 o;
|
|
105
|
+
uniform sampler2D D; uniform highp sampler2D T2; uniform ivec2 N; uniform vec2 R; uniform float T;
|
|
106
|
+
${SHAPE}
|
|
107
|
+
void main() {
|
|
108
|
+
vec2 p = uv * vec2(N); ivec2 c = ivec2(p);
|
|
109
|
+
// vorticity tints the air: red one way round, blue the other
|
|
110
|
+
vec2 r = texelFetch(T2, clamp(c + ivec2(1, 0), ivec2(0), N - 1), 0).zw, l = texelFetch(T2, clamp(c - ivec2(1, 0), ivec2(0), N - 1), 0).zw;
|
|
111
|
+
vec2 t = texelFetch(T2, clamp(c + ivec2(0, 1), ivec2(0), N - 1), 0).zw, b = texelFetch(T2, clamp(c - ivec2(0, 1), ivec2(0), N - 1), 0).zw;
|
|
112
|
+
float w = (r.y - l.y - t.x + b.x) * 8.;
|
|
113
|
+
vec3 col = vec3(.026, .03, .042) + vec3(.55, .14, .1) * min(max(w, 0.), 1.) * .3 + vec3(.08, .22, .55) * min(max(-w, 0.), 1.) * .3;
|
|
114
|
+
vec3 s = texture(D, uv).rgb;
|
|
115
|
+
col += s * 1.5; col = col / (1. + col * .45);
|
|
116
|
+
// the body: a pale solid with a soft rim
|
|
117
|
+
float d = body(p), px = float(N.y) / R.y;
|
|
118
|
+
vec3 bodyC = mix(vec3(.78, .8, .84), vec3(.95, .96, .98), clamp(-d / (OB.z * .5), 0., 1.));
|
|
119
|
+
col = mix(col, bodyC, smoothstep(px, -px, d));
|
|
120
|
+
col *= 1. - .25 * pow(abs(uv.y - .5) * 2., 6.);
|
|
121
|
+
o = vec4(pow(col, vec3(.95)), 1);
|
|
122
|
+
}`;
|
|
123
|
+
|
|
124
|
+
const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s)); return s; };
|
|
125
|
+
const prog = fs => {
|
|
126
|
+
const p = gl.createProgram(); gl.attachShader(p, sh(gl.VERTEX_SHADER, QUAD)); gl.attachShader(p, sh(gl.FRAGMENT_SHADER, fs)); gl.bindAttribLocation(p, 0, 'p'); gl.linkProgram(p);
|
|
127
|
+
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p));
|
|
128
|
+
const u = {}; for (let i = 0, n = gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i < n; i++) { const nm = gl.getActiveUniform(p, i).name; u[nm] = gl.getUniformLocation(p, nm); }
|
|
129
|
+
return { p, u };
|
|
130
|
+
};
|
|
131
|
+
const stepP = prog(stepFS), smokeP = prog(smokeFS), showP = prog(showFS);
|
|
132
|
+
const quad = gl.createVertexArray(); gl.bindVertexArray(quad);
|
|
133
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
|
|
134
|
+
gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
135
|
+
|
|
136
|
+
const tex = (w, h, ifmt, type, filt, data = null) => {
|
|
137
|
+
const t = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, t); gl.texImage2D(gl.TEXTURE_2D, 0, ifmt, w, h, 0, gl.RGBA, type, data);
|
|
138
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filt); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filt);
|
|
139
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
140
|
+
return t;
|
|
141
|
+
};
|
|
142
|
+
let lat = [], smoke = [];
|
|
143
|
+
const W9 = [4 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 36, 1 / 36, 1 / 36, 1 / 36], EX = [0, 1, 0, -1, 0, 1, -1, -1, 1];
|
|
144
|
+
function build() {
|
|
145
|
+
for (const L of lat) { L.t.forEach(t => gl.deleteTexture(t)); gl.deleteFramebuffer(L.fb); }
|
|
146
|
+
for (const S of smoke) { gl.deleteTexture(S.t); gl.deleteFramebuffer(S.fb); }
|
|
147
|
+
const a = (stage.clientWidth || 1) / (stage.clientHeight || 1);
|
|
148
|
+
NX = 480; NY = Math.max(120, Math.min(360, Math.round(NX / a)));
|
|
149
|
+
// start everywhere at the inflow's equilibrium
|
|
150
|
+
const eq = EX.map((ex, i) => { const eu = ex * U0; return W9[i] * (1 + 3 * eu + 4.5 * eu * eu - 1.5 * U0 * U0); });
|
|
151
|
+
const d0 = new Float32Array(NX * NY * 4), d1 = new Float32Array(NX * NY * 4), d2 = new Float32Array(NX * NY * 4);
|
|
152
|
+
for (let i = 0; i < NX * NY; i++) { d0.set(eq.slice(0, 4), i * 4); d1.set(eq.slice(4, 8), i * 4); d2.set([eq[8], 1, U0, 0], i * 4); }
|
|
153
|
+
lat = [0, 1].map(() => {
|
|
154
|
+
const t = [d0, d1, d2].map(d => tex(NX, NY, gl.RGBA32F, gl.FLOAT, gl.NEAREST, d));
|
|
155
|
+
const fb = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
156
|
+
t.forEach((x, i) => gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, x, 0));
|
|
157
|
+
gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2]);
|
|
158
|
+
return { t, fb };
|
|
159
|
+
});
|
|
160
|
+
smoke = [0, 1, 2].map(() => { const t = tex(NX * 2, NY * 2, gl.RGBA16F, gl.HALF_FLOAT, gl.LINEAR); const fb = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fb); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t, 0); return { t, fb }; });
|
|
161
|
+
for (const S of smoke) { gl.bindFramebuffer(gl.FRAMEBUFFER, S.fb); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); }
|
|
162
|
+
ob.x = NX * 0.24; ob.y = NY * 0.5; ob.tx = ob.x; ob.ty = ob.y;
|
|
163
|
+
}
|
|
164
|
+
const ob = { x: 0, y: 0, tx: 0, ty: 0, vx: 0, vy: 0, drag: false };
|
|
165
|
+
let W = 1, H = 1, built = '';
|
|
166
|
+
const resize = () => {
|
|
167
|
+
const d = Math.min(devicePixelRatio, 2); W = canvas.width = Math.max(1, (stage.clientWidth * d) | 0); H = canvas.height = Math.max(1, (stage.clientHeight * d) | 0);
|
|
168
|
+
const key = Math.round(((stage.clientWidth || 1) / (stage.clientHeight || 1)) * 20);
|
|
169
|
+
if (key !== built) { built = key; build(); } // a new shape of stage needs a new lattice
|
|
170
|
+
};
|
|
171
|
+
const ro = new ResizeObserver(resize); ro.observe(stage); resize();
|
|
172
|
+
|
|
173
|
+
// drag the body
|
|
174
|
+
const toCell = e => { const r = canvas.getBoundingClientRect(); return [((e.clientX - r.left) / r.width) * NX, (1 - (e.clientY - r.top) / r.height) * NY]; };
|
|
175
|
+
const down = e => { const [x, y] = toCell(e); if (Math.hypot(x - ob.x, y - ob.y) < NY * 0.2) { ob.drag = true; canvas.setPointerCapture(e.pointerId); canvas.style.cursor = 'grabbing'; } };
|
|
176
|
+
const move = e => { if (!ob.drag) return; const [x, y] = toCell(e); ob.tx = Math.min(NX * 0.6, Math.max(NY * 0.15, x)); ob.ty = Math.min(NY * 0.85, Math.max(NY * 0.15, y)); };
|
|
177
|
+
const up = () => { ob.drag = false; canvas.style.cursor = 'grab'; };
|
|
178
|
+
canvas.addEventListener('pointerdown', down); canvas.addEventListener('pointermove', move); canvas.addEventListener('pointerup', up); canvas.addEventListener('pointercancel', up);
|
|
179
|
+
|
|
180
|
+
let raf, last = performance.now(), t = 0, cur = 0, sCur = 0, shapeT = 0, shape = 0;
|
|
181
|
+
const ANG = [0, -0.21, 0]; // the wing flies at 12° (it stalls and sheds)
|
|
182
|
+
function frame(now) {
|
|
183
|
+
const dt = Math.min(0.05, (now - last) / 1000); last = now; t += dt;
|
|
184
|
+
shapeT += dt; if (shapeT > 14) { shapeT = 0; shape = (shape + 1) % 3; }
|
|
185
|
+
// left alone, the body bobs gently, which keeps the wake lively
|
|
186
|
+
if (!ob.drag) { ob.tx = NX * 0.24; ob.ty = NY * (0.5 + 0.06 * Math.sin(t * 0.7)); }
|
|
187
|
+
const steps = Math.max(1, Math.round(10 * PARAMS.speed));
|
|
188
|
+
const nx = ob.x + (ob.tx - ob.x) * Math.min(1, dt * 8), ny = ob.y + (ob.ty - ob.y) * Math.min(1, dt * 8);
|
|
189
|
+
ob.vx = Math.max(-0.08, Math.min(0.08, (nx - ob.x) / steps)); ob.vy = Math.max(-0.08, Math.min(0.08, (ny - ob.y) / steps));
|
|
190
|
+
const D = NY * 0.15, nu = (U0 * D) / Math.max(40, PARAMS.reynolds), tau = Math.max(0.503, 3 * nu + 0.5);
|
|
191
|
+
gl.useProgram(stepP.p); gl.bindVertexArray(quad); gl.viewport(0, 0, NX, NY);
|
|
192
|
+
gl.uniform1i(stepP.u.T0, 0); gl.uniform1i(stepP.u.T1, 1); gl.uniform1i(stepP.u.T2, 2);
|
|
193
|
+
gl.uniform2i(stepP.u.N, NX, NY); gl.uniform1f(stepP.u.TAU, tau); gl.uniform1f(stepP.u.U, U0); gl.uniform1i(stepP.u.SH, shape); gl.uniform2f(stepP.u.OV, ob.vx, ob.vy);
|
|
194
|
+
for (let s = 0; s < steps; s++) {
|
|
195
|
+
ob.x += ob.vx; ob.y += ob.vy;
|
|
196
|
+
gl.uniform4f(stepP.u.OB, ob.x, ob.y, D, ANG[shape]);
|
|
197
|
+
const src = lat[cur], dst = lat[1 - cur];
|
|
198
|
+
src.t.forEach((x, i) => { gl.activeTexture(gl.TEXTURE0 + i); gl.bindTexture(gl.TEXTURE_2D, x); });
|
|
199
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb); gl.drawArrays(gl.TRIANGLES, 0, 3); cur = 1 - cur;
|
|
200
|
+
}
|
|
201
|
+
// smoke
|
|
202
|
+
gl.useProgram(smokeP.p); gl.viewport(0, 0, NX * 2, NY * 2);
|
|
203
|
+
const next = (sCur + 1) % 2, hat = smoke[2];
|
|
204
|
+
gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, smoke[sCur].t); gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, lat[cur].t[2]);
|
|
205
|
+
gl.activeTexture(gl.TEXTURE2); gl.bindTexture(gl.TEXTURE_2D, hat.t);
|
|
206
|
+
gl.uniform1i(smokeP.u.D, 0); gl.uniform1i(smokeP.u.T2, 1); gl.uniform1i(smokeP.u.HAT, 2); gl.uniform2i(smokeP.u.N, NX, NY); gl.uniform1f(smokeP.u.K, steps);
|
|
207
|
+
gl.uniform1f(smokeP.u.LINES, Math.round(PARAMS.smoke)); gl.uniform1f(smokeP.u.T, t); gl.uniform4f(smokeP.u.OB, ob.x, ob.y, D, ANG[shape]); gl.uniform1i(smokeP.u.SH, shape);
|
|
208
|
+
gl.uniform1i(smokeP.u.MODE, 0); gl.bindTexture(gl.TEXTURE_2D, null); // hat is the target of the predict pass
|
|
209
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, hat.fb); gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
210
|
+
gl.bindTexture(gl.TEXTURE_2D, hat.t); gl.uniform1i(smokeP.u.MODE, 1);
|
|
211
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, smoke[next].fb); gl.drawArrays(gl.TRIANGLES, 0, 3); sCur = next;
|
|
212
|
+
// show
|
|
213
|
+
gl.useProgram(showP.p); gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.viewport(0, 0, W, H);
|
|
214
|
+
gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, smoke[sCur].t); gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, lat[cur].t[2]);
|
|
215
|
+
gl.uniform1i(showP.u.D, 0); gl.uniform1i(showP.u.T2, 1); gl.uniform2i(showP.u.N, NX, NY); gl.uniform2f(showP.u.R, W, H); gl.uniform1f(showP.u.T, t);
|
|
216
|
+
gl.uniform4f(showP.u.OB, ob.x, ob.y, D, ANG[shape]); gl.uniform1i(showP.u.SH, shape);
|
|
217
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
218
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
219
|
+
raf = requestAnimationFrame(frame);
|
|
220
|
+
}
|
|
221
|
+
raf = requestAnimationFrame(frame);
|
|
222
|
+
return () => {
|
|
223
|
+
cancelAnimationFrame(raf); ro.disconnect();
|
|
224
|
+
canvas.removeEventListener('pointerdown', down); canvas.removeEventListener('pointermove', move); canvas.removeEventListener('pointerup', up); canvas.removeEventListener('pointercancel', up);
|
|
225
|
+
gl.getExtension('WEBGL_lose_context')?.loseContext(); canvas.remove();
|
|
226
|
+
};
|
|
227
|
+
}
|