176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
docs: sync the 3D & Advanced content sheet with the frame-rate fixes
matin789da557c6ef
diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.mdindex ca055288..dc53b4c3 100644--- a/docs/superpowers/plans/2026-09-29-3d-content.md+++ b/docs/superpowers/plans/2026-09-29-3d-content.md@@ -48,7 +48,7 @@ Ten pages move their picture with `requestAnimationFrame`: 3D Model Orbit, Canva- The loop keeps exactly one pending frame in `raf`. The function that starts it, `start()`, returns at once when `raf` is set; otherwise it forgets the time of the last frame and requests a frame. On Cloth / Soft-Body Simulation it is called `resume()`, because that page's own `start()` rebuilds the cloth (see its section).- The page listens for `hb:pause`, registered at the top level of its inline script. Paused: `cancelAnimationFrame(raf); raf=null;` and the picture on screen stays. Not paused: `start()` (`resume()` on Cloth), which carries on from the current state. The page keeps its own `paused` flag from this event; the old panel's Pause button, its label code and its flag handling go.-- Each page's frame gate stays as it is today (`if(dt<16)return`, 12ms on GPGPU Particle System).+- Each page's frame gate stays as it is today (`if(dt<16)return`), except on Canvas Particle Effect and GPGPU Particle System, which have no fixed gate any more: they look at every frame the screen offers and draw only when a Trails wash or a physics pass is due (see their sections).- **Clocks.** Where the movement follows a clock, the page keeps its own, which adds up each frame's time (capped, and counted afresh from each start), so Play never jumps. Where a speed multiplies the clock inside a shader (Ray Marching's camera, Volumetric Smoke's rise), the page adds up the speed-weighted step itself, so a new speed never makes the picture jump; the sections say which uniform replaces which product.- **The first picture:** the page draws a frame at load, before the loop starts, so a loop that is paused on arrival never shows an empty stage. The sections name the call.- **While paused,** a setting change or a resize draws the picture again so the change shows, without moving anything (a canvas that fades instead of clearing, as with Trails, is cleared first, so no ghost of the old picture stays under the new one). This is the loop rule "changing a setting while paused shows the new setting without starting the loop again". Most pages already do this ("repaint while paused"); the sections name the function. Listeners that watched the old `aside` for `input` now watch the Try it step for `click` and `change` (choice buttons send `click`).@@ -139,7 +139,7 @@ Canvas Particle Effect's cost is its links: one `stroke()` per line, thousands a- **Watch it help line:** default- **Player bar:** Pause (page) · Slow motion (page)- **Sequence:** the WebGL loop as in the preamble (`render(ts)`, 16ms gate). Each drawn frame:- - with Movement on Spins, `ry += SY*.01*k` and `rx += SX*.01*k*(Math.sin(clock*.0003)*.5+.5)`, where `k` is 1, or a third while Slow motion is on, and `clock` is the page's own clock (in place of today's `ts`, see the preamble), which adds `Math.min(dt,50)*k` for each drawn frame; the forward roll speeds up and slows down over about 21 seconds;+ - with Movement on Spins, `ry += SY*.01*s` and `rx += SX*.01*s*(Math.sin(clock*.0003)*.5+.5)`, where `s = Math.min(dt,50)/FRAME*(slow ? 1/3 : 1)` is the frame's time in 60 Hz frames (`FRAME = 1000/60`), a third of that while Slow motion is on, and `clock` is the page's own clock (in place of today's `ts`, see the preamble), which adds `s*FRAME` (that is, `Math.min(dt,50)` times 1, or a third) for each drawn frame; the forward roll speeds up and slows down over about 21 seconds;- with Follows the pointer, `rx = mouseNY*1.2` and `ry = mouseNX*1.5`;- then `draw()`.@@ -192,7 +192,7 @@ Canvas Particle Effect's cost is its links: one `stroke()` per line, thousands a|-----------|---------|--------|| Shape | Cube | The object that is drawn: a cube, a sphere, a ring or a four-sided pyramid || Movement | Spins | Spins turns it by itself; Follows the pointer turns it to face your pointer or finger |- | Speed | Normal | How fast it spins: slow is about 17°, normal 27° and fast 45° a second |+ | Speed | Normal | How fast it spins: slow is about 17°, normal 27° and fast 45° a second, on any screen || Tumbles as it spins | on | Also rolls it forward, at a speed that rises and falls, so the top and bottom come into view || Distance | Medium | How far away the camera is: close looks bigger, far looks smaller; the lens stays the same || Color | Blue | The object's color; the lighting adds the shading and the highlight |@@ -202,10 +202,11 @@ Canvas Particle Effect's cost is its links: one `stroke()` per line, thousands a- [Scroll-Driven 3D Rotation](../scroll-driven-3d-rotation/) — scrolling turns the object instead of time- [Parallax 3D Tilt](../parallax-3d-tilt/) — a flat card leans in 3D toward the pointer- [WebGL Shader Animation](../webgl-shader-animation/) — the same WebGL setup, painting a pattern instead of a shape-- **README How it works:** unchanged, except the fragment shader's view vector line, which becomes `vec3 V = normalize(-vP);` as on the page (`vP` is already in camera space, so the camera is at the origin); and the vertex shader's uniform comment reads `/* model-view-projection, model-view */`, because `uM` holds the model-view matrix-- **README Production notes:** unchanged+- **README How it works:** unchanged, except the fragment shader's view vector line, which becomes `vec3 V = normalize(-vP);` as on the page (`vP` is already in camera space, so the camera is at the origin); and the vertex shader's uniform comment reads `/* model-view-projection, model-view */`, because `uM` holds the model-view matrix. The frame-rate fix (below) adds a "**Turning**" paragraph and a snippet (`FRAME`, `step`, `ry`, `rx`) after the projection snippet.+- **README Production notes:** unchanged, except that the frame-rate fix (below) adds a bullet after the first: "**Time, not frames**: a fixed turn per frame would spin the shape twice as fast on a 120 Hz screen and half as fast on a 30 Hz phone. Scale each turn by the time since the last frame, cap that time (this demo uses 50 ms) so a tab that comes back does not lurch, and let a returning tab start from its next frame."- **Category line:** `06.01 · 3D & Advanced`- **Pager:** Previous: none · Next: Scroll-Driven 3D Rotation (`../scroll-driven-3d-rotation/`)+- **Frame-rate fix (wrap-up):** each drawn frame turns the shape by `s`, the time since the last drawn frame in 60 Hz frames (`FRAME = 1000/60`, at most 50 ms), a third of that while Slow motion is on, so the spin and the roll keep the same speed on a 30, 60 or 144 Hz screen. Following the pointer is the same at every rate. The 16 ms gate stays, as a cap of 60 drawn frames a second. The first frame after a start, a Play or a return from a hidden tab (a `visibilitychange` listener sets the last frame time back to `null`) only takes the time. README: the "Turning" paragraph and snippet in How it works, the Speed row of Key parameters (now "… a second, on any screen") and a "Time, not frames" Production note.---@@ -217,7 +218,7 @@ Canvas Particle Effect's cost is its links: one `stroke()` per line, thousands a- **Scroller:** the `.stage` itself. Its own rule keeps `overflow-y:auto;overflow-x:hidden`, which wins over the shared `overflow:hidden`; no `data-hb-scroller`.- **What scrolling shows:** the cube stays pinned in the middle of the stage while the stage scrolls through content four stage-heights tall. The scroll position, from the top to the end, moves the cube through four poses in turn: a quarter turn to the side, a forward tilt, growing larger, then turning round to show its back. It glides between them while Smooth follow is on. Scrolling back runs it in reverse.- **Player bar:** Play · Back to top (the shared script runs both). No Slow motion.-- **Sequence:** unchanged: `scroll` → `onScroll()` → progress from 0 to 1 → `applyRotation(p)`, then `tick()` eases the cube toward its pose while Smooth follow is on, or `render()` sets it at once. The ResizeObserver stays. Back to top jumps the stage to its top, and the `scroll` event that causes brings the cube back to its first pose.+- **Sequence:** unchanged, apart from the frame-rate fix below: `scroll` → `onScroll()` → progress from 0 to 1 → `applyRotation(p)`, then `tick(now)` eases the cube toward its pose while Smooth follow is on (a tenth of the gap left for every 1/60 s), or `render()` sets it at once. The ResizeObserver stays. Back to top jumps the stage to its top, and the `scroll` event that causes brings the cube back to its first pose.- `onScroll()` loses its readout lines (the progress bar, the percentage and the Scroll Progress slider).- `render()` loses the Rotation X, Rotation Y and Scale readouts.- `applyRotation()` loses the chapter dots, name and description.@@ -262,16 +263,17 @@ None: leave out the `details.hb-options` block.| Parameter | Default | Effect ||-----------|---------|--------|| Turn amount | Normal | How far every pose turns the cube: less is 0.6, normal 1 and more 1.6 times the planned angles; at normal the last pose shows the cube's back |- | Smooth follow | on | The cube closes a tenth of the gap to its pose every frame, so it glides after the scroll; off, it follows the scroll exactly |+ | Smooth follow | on | The cube closes a tenth of the gap to its pose for every sixtieth of a second, so it glides after the scroll and catches up in the same time on every screen; off, it follows the scroll exactly |- **README See also:**- [3D Model Orbit](../3d-model-orbit/) — time turns the object instead of scrolling- [Scrub Animation](../../01-scroll-based/scrub-animation/) — scroll position drives any animation, without 3D- [Sticky Section](../../01-scroll-based/sticky-section/) — the pinning that keeps the object in view-- **README How it works:** unchanged-- **README Production notes:** unchanged+- **README How it works:** unchanged, except that the frame-rate fix (below) changes the Smooth follow snippet (`FRAME`, `last`, `dt`, `ease = 1 - Math.pow(0.9, dt / FRAME)`) and adds a paragraph after it on the share to close in one frame, and a sentence saying that the first frame after the loop starts again counts as one 1/60 s.+- **README Production notes:** unchanged, except that the frame-rate fix (below) adds a bullet after the GSAP ScrollTrigger one: "**Time, not frames**: easing that closes a fixed share of the gap on every frame follows the screen's refresh rate. Scale the share by the time since the last frame, as above, and cap that time (this demo uses 50 ms)."- **Category line:** `06.02 · 3D & Advanced`- **Pager:** Previous: 3D Model Orbit (`../3d-model-orbit/`) · Next: Parallax 3D Tilt (`../parallax-3d-tilt/`)+- **Frame-rate fix (wrap-up):** `tick(now)` eases the cube by `ease = 1 - .9 ** (dt / FRAME)` of the gap to its pose, with `FRAME = 1000/60` and `dt` the time since the last frame (at most 50 ms), so a tenth of the gap closes for every 1/60 s and the cube catches up in the same time on a 30, 60 or 144 Hz screen. `applyRotation()` sets the last frame time to `null` whenever it starts the loop again, and a first frame with no earlier time counts as one 1/60 s. At 60 Hz nothing changes. README: the snippet and its paragraph, the Smooth follow row of Key parameters and a "Time, not frames" Production note.---@@ -361,11 +363,11 @@ None: leave out the `details.hb-options` block.- **Description:** Dots drift, link up when close, and dodge your pointer. Best for tech sites.- **Watch it help line:** It moves by itself, and the dots move away from your pointer or finger. Pause it to look closely, or turn on slow motion.- **Player bar:** Pause (page) · Slow motion (page)-- **Sequence:** the canvas loop as in the preamble (`loop(t)`, 16ms gate). Each drawn frame runs `update()` on every particle (the pointer's push or pull within 120px, the speed cap, the move, the bounce), then `draw()`.+- **Sequence:** the canvas loop as in the preamble (`loop(t)`, with no fixed gate: a frame is drawn only when a Trails wash is due, see the frame-rate fix below). Each drawn frame runs `update(k)` on every particle (the pointer's push or pull within 120px, the speed cap, the move, the bounce), then `draw(washes)`.- **The links in six batches:** `draw()` puts every link into one of six paths by its opacity step and strokes each path once, in place of one `stroke()` per link. For a pair closer than Link distance, `k = Math.min(5, Math.floor((1 - d2/d2max) * 6))` picks the path, and path k is stroked at opacity `(k + 0.5) / 6 * 0.4` (today's opacity, `(1 - d2/d2max) * 0.4`, in six steps). `ctx.lineWidth=.5` stays, set once before the six strokes. The dots are drawn as today.- **The first picture:** `draw()` runs at load, after `spawn()`. **While paused,** every setting and a resize call `redraw()`, which clears the canvas and then calls `draw()` (today's `if(paused)draw()` calls). With Trails on, `draw()` only lays a 15% wash over what is already there, so without the clearing a new Link distance, number of dots or color would show on top of the old picture.- **The resize handler** returns at once when the stage's size has not changed (`if(stage.clientWidth===W&&stage.clientHeight===H)return;`, as on Cloth / Soft-Body Simulation), so a phone's address bar showing or hiding does not scatter the dots again.-- **Slow motion:** while the switch is on, `update()` moves each particle by a third of its velocity (`this.x += this.vx/3`, and the same for y), and the pointer's push or pull adds a third of today's amount, from the next frame. The speed cap stays.+- **Slow motion:** while the switch is on, `update(k)` gets a third of its usual `k`: it moves each particle by a third of its velocity (`this.x += this.vx*k`, and the same for y), and the pointer's push or pull adds a third of today's amount, from the next frame. The speed cap stays. The Trails wash is not slowed (see the frame-rate fix below).- **Reduced motion:** the page's reduced-motion branch (paused at load with one frame drawn) goes (see the preamble).- **Stage font:** no text on the stage.- **Stage:** only the canvas. The fps badge goes. `hb-dots`: no (its dots would mix with the particles). Default height.@@ -412,7 +414,7 @@ None: leave out the `details.hb-options` block.| Pointer effect | Push | What the pointer or a finger does to dots within 120px: pushes them away, pulls them in, or nothing || Number of particles | Medium | Few is 250, medium 500 and many 800 dots on computers; tablets draw 60, 90 and 120, and phones 30, 45 and 60, which keeps them smooth || Link distance | Medium | How close two dots must be to join with a line: short is 70px, medium 100px and long 150px; none draws no lines |- | Speed | Normal | How fast the dots drift: slow is 0.5, normal 0.8 and fast 1.3 (the fastest dots' pixels a frame); slow feels calm, fast looks busy |+ | Speed | Normal | How fast the dots drift: slow is 0.5, normal 0.8 and fast 1.3 (the fastest dots' pixels for every sixtieth of a second, on any screen); slow feels calm, fast looks busy || Color | Blue | The color of the dots and lines || Trails | off | Each dot leaves a fading streak, because the canvas is only partly cleared between frames |@@ -420,7 +422,7 @@ None: leave out the `details.hb-options` block.- [GPGPU Particle System](../gpgpu-particle-system/) — tens of thousands of particles moved on the graphics chip- [Noise-Based Motion](../noise-based-motion/) — dots moved by smooth noise instead of physics- [Particle Constellation](../../07-ambient-background/particle-constellation/) — calmer linked dots, as a background-- **README How it works:** the Connections snippet becomes the batched version, and one sentence follows it:+- **README How it works:** the Connections snippet becomes the batched version, and one sentence follows it (the frame-rate fix, below, also changes the first snippet to `update(k)` and adds a `frame(elapsed)` snippet with a paragraph after it):```js// Every link goes into one of six paths by its opacity; each path is stroked once@@ -448,9 +450,12 @@ None: leave out the `details.hb-options` block.- **README Production notes:**- The `ctx.clearRect` bullet's "(enable "trails" toggle in the demo)" becomes "(turn on Trails in the demo)".- Add a bullet after "O(n²) limit": "**Phones and tablets**: the demo draws 30 to 60 dots on phones (screens 600px wide or less, or 500px tall or less when held sideways) and 60 to 120 on other screens up to 1024px wide, and strokes the links in six batches instead of one call per line."+ - The same bullet gains: "The demo washes once for every 1/60 s of frame time (twice on a 30 Hz screen, once on each drawn frame from 59.94 Hz up), always at 15% and whatever Slow motion does, so the streaks last as long on a 30 Hz phone as on a 60 Hz screen. One smaller wash would fade the same amount, but an 8-bit canvas rounds it differently, and the faint leftovers of a trail would end up another color."+ - After it comes a new bullet: "**Time, not frames**: a fixed step per frame follows the screen's refresh rate, so the dots would drift twice as fast at 120 Hz and half as fast at 30 Hz. Cap the time of one frame (this demo uses 50 ms) so a tab that comes back does not lurch, and let a returning tab start from its next frame."- The rest is unchanged.- **Category line:** `06.04 · 3D & Advanced`- **Pager:** Previous: Parallax 3D Tilt (`../parallax-3d-tilt/`) · Next: Fluid / Liquid Simulation (`../fluid-simulation/`)+- **Frame-rate fix (wrap-up):** each drawn frame moves the dots by `k = steps * (slow ? 1/3 : 1)`, where `steps` is the time since the last drawn frame in 60 Hz frames (`FRAME = 1000/60`, at most 50 ms), so they drift at the same speed on every screen (`update(k)` scales the pointer's push or pull and the move). The Trails wash is not scaled: it is the same 15% laid over the picture once for every 1/60 s (`washes`; two on a 30 Hz frame), and Slow motion does not slow it. `owed` carries the part of a step not laid yet, a `steps` value within 5% of a whole number counts as that number, and the count is rounded with a 0.05 bias, so a 59.94 or 60.06 Hz screen (or a little timestamp noise) still washes exactly once a frame, and the half step of an exact 120 or 240 Hz screen does not sit on a tie. A frame with no wash due draws nothing and changes nothing, so its time carries to the next frame; that replaces the 16 ms gate (Trails off included) and keeps drawing near 60 pictures a second on a faster screen. `start()` and a `visibilitychange` listener set the last frame time back to `null` and `owed` to 0, and the first frame after a start only takes the time. README: the snippets and paragraph above in How it works, the Speed row of Key parameters and two Production notes.---@@ -693,12 +698,12 @@ None: leave out the `details.hb-options` block.- **Description:** Smooth noise makes dots sway and a blob ripple. Best for calm backgrounds.- **Watch it help line:** default- **Player bar:** Pause (page) · Slow motion (page)-- **Sequence:** the canvas loop as in the preamble (`loop(ts)`, 16ms gate). Each drawn frame adds Speed × 0.01 to `t` and draws with `frame()`.+- **Sequence:** the canvas loop as in the preamble (`loop(ts)`, 16ms gate). Each drawn frame adds Speed × 0.01 × `dt / FRAME` to `t` (`FRAME = 1000/60`, `dt` at most 50 ms; see the frame-rate fix below) and draws with `frame()`.- **The dot spacing:** `drawGrid()` uses `SPACE` pixels as its step, in place of `Math.max(4,Math.floor(W/GRID))`. Today the grid is set by columns across the stage, so a narrow phone stage gets a finer grid and more dots than a laptop (340 dots on a phone stage against 160 on the stage of a 1280×800 screen). Spacing in pixels keeps the same look on every screen: Medium, 48px, is today's 20 columns on a 960px laptop stage.- **The first picture:** `frame()` runs at load. **While paused,** every setting (Try it's `click` and `change`, in place of today's `aside` listener) and a resize call `frame()`.- **The resize handler** returns at once when the stage's size has not changed (`if(stage.clientWidth===W&&stage.clientHeight===H)return;`, as on Canvas Particle Effect and Cloth / Soft-Body Simulation): setting a 2D canvas's size blanks it, and a phone's address bar showing or hiding also fires `resize`, which on a 90 or 120 Hz phone could flash the stage empty for a frame.- **The blob ripples.** The edge reads the noise along a circle of radius `RING × SCALE` with `RING = 48`, and the inner ring along `RING_IN × SCALE` with `RING_IN = 32`, in place of today's 12 and 8. Today's circle was so small that the noise hardly varied along it: at the default the edge departed only 12px from round (median, on a 106px radius, with one lobe) while the whole blob breathed 39px (86 to 125px), so it read as a breathing circle, not the ripple the Description and the prompt promise. Measured on the page over 120s of noise (the drawn outline, largest minus smallest radius): before, 11.5px median, 1.1 lobes; now, at the default settings, 33px median (25 to 41px from the 10th to the 90th percentile, 44px at most), about two lobes (2.3), and the whole blob breathes 20px (96 to 115px). The choices stay meaningful: Pattern size Large 23px and 1.4 lobes, Medium 33px and 2.3, Small 37px and 4.4 (busy); Wobble Small 16px, Medium 33px, Large 55px (73px at most). The largest ripple (Large wobble, Small pattern size) stays inside the canvas on the 286×298, 341×298, 745×258 and 958×378 stages. The edge is drawn with 96 points, up from 48 (`VERTS`), because the wider ripple made 48 show corners at the busy settings: the sharpest turn between neighbouring segments was 57° with 48 points at Small pattern size and Medium wobble (95° with Large wobble) and is 36° (69°) with 96; at the default settings it is 11° with 96 (21° with 48), where a plain circle of 96 points turns 3.8°. The blob still draws in under 1ms a frame on the throttled phone (181 of 180 frames in 3s on the phone, the sideways phone and the 320px phone). The dots are untouched.-- **Slow motion:** while the switch is on, each drawn frame adds a third: `t += SPD*.01/3`, from the next frame.+- **Slow motion:** while the switch is on, each drawn frame adds a third: `t += SPD*.01*(Math.min(dt,50)/FRAME)/3`, from the next frame.- **Reduced motion:** the page's reduced-motion branch goes (see the preamble).- **Stage font:** no text on the stage.- **Stage:** only the canvas. The fps badge goes. `hb-dots`: no (it would mix with the field of dots). Default height.@@ -744,7 +749,7 @@ None: leave out the `details.hb-options` block.|-----------|---------|--------|| Shape | Field of dots | A field of dots that sway, or one blob whose outline ripples || Pattern size | Medium | How big the noise's patterns are: large moves big areas together, small looks busy and fine |- | Speed | Normal | How fast the noise moves along: slow is 0.3, normal 0.5 and fast 0.8 |+ | Speed | Normal | How fast the noise moves along: slow is 0.3, normal 0.5 and fast 0.8. Every sixtieth of a second the noise moves on by 0.01 times this, so the speed is the same on every screen || Wobble | Medium | How far each dot, or the blob's edge, moves: small is 6px, medium 12px and large 20px || Space between dots | Medium | The distance between dots in the field: wide is 64px, medium 48px and tight 32px; smaller stages draw fewer dots || Color | Blue | The color of the dots or the blob |@@ -753,10 +758,11 @@ None: leave out the `details.hb-options` block.- [Canvas Particle Effect](../canvas-particle-effect/) — dots moved by simple physics instead of noise- [Flow Field](../../07-ambient-background/flow-field/) — particles follow a noise field and leave trails- [Volumetric Smoke / 3D Noise](../volumetric-smoke/) — the same kind of noise, in 3D, drawn as smoke-- **README How it works:** unchanged, plus one sentence after the wind-field snippet: "The demo sets `step` as a spacing in pixels rather than a number of columns, so a phone's smaller stage draws fewer dots at the same spacing." The Blob snippet reads `48 * SCALE` where it read `12 * SCALE`, with one sentence after it: "The noise is read along a circle of radius `48 * SCALE`. A tiny circle would see almost one value, so the whole edge would only swell and shrink together; this one spans about two bumps of noise at the default size, so the edge ripples."-- **README Production notes:** unchanged+- **README How it works:** unchanged, plus one sentence after the wind-field snippet: "The demo sets `step` as a spacing in pixels rather than a number of columns, so a phone's smaller stage draws fewer dots at the same spacing." The Blob snippet reads `48 * SCALE` where it read `12 * SCALE`, with one sentence after it: "The noise is read along a circle of radius `48 * SCALE`. A tiny circle would see almost one value, so the whole edge would only swell and shrink together; this one spans about two bumps of noise at the default size, so the edge ripples." The frame-rate fix (below) also changes the last line of the wind-field snippet to `time += speed * 0.01 * (dt / FRAME); // advance through noise volume` and adds a paragraph after that snippet, on `dt` and `FRAME`.+- **README Production notes:** unchanged, except that the frame-rate fix (below) adds a bullet after the `glsl-noise` one: "**Time, not frames**: move through the noise by the time since the last frame, because a fixed step per frame follows the screen's refresh rate. Cap that time (this demo uses 50 ms), or a tab that comes back after a minute would jump ahead by a minute of motion, and let a returning tab start from its next frame."- **Category line:** `06.08 · 3D & Advanced`- **Pager:** Previous: WebGL Shader Animation (`../webgl-shader-animation/`) · Next: SVG Path Animation (`../svg-path-animation/`)+- **Frame-rate fix (wrap-up):** `t += SPD * .01 * (Math.min(dt, 50) / FRAME) / (slow ? 3 : 1)`, with `FRAME = 1000/60` and `dt` the time since the last drawn frame (measured before the last frame time is updated), so the noise moves the same distance a second on a 30, 60 or 144 Hz screen. The 16 ms gate stays, as a cap of 60 drawn frames a second. A `visibilitychange` listener sets the last frame time back to `null` (as `start()` does), so the first frame after a start, a Play or a return from a hidden tab only takes the time. README: the last line of the wind-field snippet and a paragraph after it, the Speed row of Key parameters and a "Time, not frames" Production note.---@@ -1117,12 +1123,12 @@ None: leave out the `details.hb-options` block.- **Description:** Tens of thousands of particles flow on the graphics chip. Best for hero effects.- **Watch it help line:** default- **Player bar:** Pause (page) · Slow motion (page)-- **Sequence:** the WebGL 2 loop as in the preamble (`render(ts)`, 12ms gate).- - `drawFrame(t)` splits into `physics(t)` (the physics pass and the texture swap) and `paint(t)` (the drawing pass). Each drawn frame runs both.- - The page keeps its own clock, `simT` (each frame's time, at most 50ms, and nothing on the first frame after a start), in place of `(ts-startT)/1000`.+- **Sequence:** the WebGL 2 loop as in the preamble (`render(ts)`, with no fixed gate: a frame is drawn only when a physics pass is due, see the frame-rate fix below).+ - `drawFrame(t)` splits into `physics(t)` (the physics pass and the texture swap) and `paint(t)` (the drawing pass). Each drawn frame runs `physics(t, unit)` once for every pass due (at most 3), then `paint(t, false, passes)` once.+ - The page keeps its own clock, `simT`, in place of `(ts-startT)/1000`: it adds `unit/60` for each pass (`unit` is 1, or 1/3 in Slow motion), so a pause never makes the particles jump, and nothing is added on the first frame after a start.- **The first picture:** `settle()` and then `paint()` run once at load (today's `resize()` draws only while paused). `settle()` is 120 silent physics steps at the full step, whatever Slow motion says (`physics(t,step)` takes the step as a second argument and sets `uStep` to it; called without one it uses 1, or 1/3 in slow motion, as before). That is two seconds of flow, so a picture shown still (paused on arrival, or under reduced motion) already shows the flow, not the starting square cloud. It costs about 23 ms on a laptop and 11 ms on a phone with the CPU slowed four times.- **While paused,** a setting or a resize calls `paint()` only. Today's `refresh()` also ran a physics step, which moved the particles a little while paused. A change of Number of particles builds the new cloud and settles it first, so the picture shows the flow and not the starting cloud. Pressing the Number of particles or the Color that is already chosen does nothing (Color would otherwise draw the picture again and erase the streaks Trails leaves).-- **Slow motion:** the physics shader gets `uniform float uStep` (1, or 1/3 while Slow motion is on), from the next frame. Every change of velocity is multiplied by `uStep` (the four behaviours' pushes, and the vortex's and orbit's inward pulls), the damping becomes `pow(.985,uStep)`, and the move becomes `x+=vx*uStep; y+=vy*uStep`. So every particle moves a third as far each frame while its speed and the shapes the particles form stay the same. The clock adds a third of each frame's time.+- **Slow motion:** the physics shader gets `uniform float uStep` (1, or 1/3 while Slow motion is on), from the next frame. Every change of velocity is multiplied by `uStep` (the four behaviours' pushes, and the vortex's and orbit's inward pulls), the damping becomes `pow(.985,uStep)`, and the move becomes `x+=vx*uStep; y+=vy*uStep`. So every particle moves a third as far in each pass while its speed and the shapes the particles form stay the same. Passes still come 60 a second, so the Trails fade is not slowed. The clock adds a third of a 1/60 s for each pass.- **Reduced motion:** the page's reduced-motion branch goes (see the preamble).- **Stage font:** no text on the stage. The WebGL 2 message uses the site font and reads "This demo needs WebGL 2, which this browser does not offer. Try a recent Chrome, Firefox or Safari.", set with `textContent` (was "WebGL2 required for GPGPU texture ping-pong." with a `<br>`). A shader that fails to build reads "Shader failed to build: " and the browser's log; when the browser gives no log the page says "the shader did not compile" (or "the shaders did not link"), so the message is never left blank, as on Ray Marching / SDF Scene and Volumetric Smoke.- **Stage:** only the canvas. The fps, count and behaviour badges go; `.no-wgl2` stays. `hb-dots`: no. Default height.@@ -1165,7 +1171,7 @@ None: leave out the `details.hb-options` block.|-----------|---------|--------|| Movement | Flow | Flow follows a shifting field of currents; Swirl circles the middle; Attract pulls everything toward the middle; Orbit sweeps the particles round in rings || Number of particles | 65,000 | 16,000, 65,000 or 100,000 particles, one pixel each of a texture 128, 256 or 320 pixels square; phones start with 16,000 |- | Speed | Normal | How hard the rule pushes each frame: slow is 0.35, normal 0.6 and fast 1 |+ | Speed | Normal | How hard the rule pushes for every sixtieth of a second: slow is 0.35, normal 0.6 and fast 1 || Color | One color | One blue, a color from each particle's speed, or colors that slowly shift || Trails | off | Fades the last picture instead of clearing it, so each particle leaves a streak |@@ -1173,10 +1179,11 @@ None: leave out the `details.hb-options` block.- [Canvas Particle Effect](../canvas-particle-effect/) — hundreds of particles moved in JavaScript- [Fluid / Liquid Simulation](../fluid-simulation/) — a shader that melts blobs together- [WebGL Shader Animation](../webgl-shader-animation/) — shaders that paint every pixel-- **README How it works:** the physics snippet matches the new shader: after `uniform int uBehavior;` add `uniform float uStep; // 1, or 1/3 in slow motion`; the vortex's four velocity lines each end in `* uStep`; the damping line becomes `vx *= pow(0.985, uStep); vy *= pow(0.985, uStep); // damping`; and the move becomes `x += vx * uStep; y += vy * uStep;`. The rest is unchanged.-- **README Production notes:** the phone rule reads "on phones (screens 600px wide or less, or 500px tall or less)" (final fix wave).+- **README How it works:** the physics snippet matches the new shader: after `uniform int uBehavior;` add `uniform float uStep; // one 60 Hz step per pass: 1, or 1/3 in slow motion`; the vortex's four velocity lines each end in `* uStep`; the damping line becomes `vx *= pow(0.985, uStep); vy *= pow(0.985, uStep); // damping`; and the move becomes `x += vx * uStep; y += vy * uStep;`. The frame-rate fix (below) also puts a "**Time step**" paragraph in front of the ping-pong snippet, and its lead-in reads "alternate which texture is the read source each pass:". The rest is unchanged.+- **README Production notes:** the phone rule reads "on phones (screens 600px wide or less, or 500px tall or less)" (final fix wave). The frame-rate fix (below) adds a bullet after the WebGL2 one: "**Time, not frames**: a fixed step per frame would move the particles twice as fast on a 120 Hz screen and half as fast on a 30 Hz phone, and fade the trails at the same wrong rate. Step by a fixed 1/60 s from an accumulator, as above, and cap the time of one frame (this demo uses 50 ms) and the passes per frame, so a strong pull near a point settles the same on every screen. Fade once per physics pass, always by the same amount."- **Category line:** `06.13 · 3D & Advanced`- **Pager:** Previous: Ray Marching / SDF Scene (`../ray-marching-sdf/`) · Next: Image Distortion on Hover (`../image-distortion-hover/`)+- **Frame-rate fix (wrap-up):** every physics pass is exactly one 60 Hz step (`uStep` 1, or 1/3 in Slow motion), never a longer or shorter one, because the Attract rule pulls hard near the middle and settles differently for another step size. The loop looks at every frame the screen offers: `steps` is the time since the last drawn frame in steps of 1/60 s (at most 50 ms), a value within 5% of a whole number counts as that number, and `owed` carries the part of a step not run yet. A frame runs one pass for every whole step owed (1 ms of slack, at most 3), so one on a 60 Hz screen and two on a 30 Hz one; a frame with no pass due changes nothing and draws nothing, which replaces the 12 ms gate and keeps drawing near 60 pictures a second on a faster screen. A drawn frame lays the Trails fade over the picture once for every pass, always at the same 12%, so Slow motion, which still runs 60 passes a second, slows the particles but not the fade. `settle()` still runs its 120 steps of 1. `start()` and a `visibilitychange` listener set the last frame time back to `null` and `owed` to 0. README: the `uStep` comment, a "Time step" paragraph, the Speed row of Key parameters and a "Time, not frames" Production note.---@@ -1259,10 +1266,10 @@ None: leave out the `details.hb-options` block.- **Kind:** loop. The cloth sways in the wind forever; you can drag it.- **Description:** A cloth sways in the wind, and you can drag it around. Best for playful pages.- **Watch it help line:** It moves by itself. Drag the cloth to pull it, or pause it to look closely.-- **Player bar:** Pause (page) · Reset. No Slow motion: each frame is one physics step, and slowing the steps would change how stiff the cloth is.+- **Player bar:** Pause (page) · Reset. No Slow motion: every physics step is a fixed 1/60 s, and slowing the steps would change how stiff the cloth is.- **Reset:** hangs a fresh cloth (`initCloth(paused)`, today's Reset cloth). While paused it settles the fresh cloth first (see the first picture below), so it shows the cloth already hanging, still; while playing it hangs the cloth flat and the loop lets it fall.-- **Sequence:** the canvas loop as in the preamble (`loop(ts)`, 16ms gate). Each drawn frame runs `update()`, then `draw()`, as today.- - **Two functions in place of today's `start()`,** which both rebuilt the cloth and started the loop: `rebuild(settle)` is `resize(); initCloth(settle);`, for Detail and for a resize (both pass `paused` on as `settle`); `resume()` is `if(raf)return; lastT=performance.now(); raf=requestAnimationFrame(loop);`, for Play (`hb:pause` with `paused` false). At load the page runs `rebuild(true)`, then `resume()`.+- **Sequence:** the canvas loop as in the preamble (`loop(ts)`, 16ms gate). Each drawn frame runs `update()` once for every 1/60 s that has passed since the last one, at most three (see the frame-rate fix below), then `draw()`.+ - **Two functions in place of today's `start()`,** which both rebuilt the cloth and started the loop: `rebuild(settle)` is `resize(); initCloth(settle);`, for Detail and for a resize (both pass `paused` on as `settle`); `resume()` is `if(raf!==null)return; lastT=null; behind=0; raf=requestAnimationFrame(loop);`, for Play (`hb:pause` with `paused` false). At load the page runs `rebuild(true)`, then `resume()`.- **The first picture:** `initCloth(settle)` draws the cloth (today it draws only while paused). With `settle` it first runs 120 silent physics steps (`windT+=16; update();` each, two seconds of a 60 fps loop), so a cloth shown still (at load, on a paused arrival or under reduced motion) already hangs and sways, not the flat coloured rectangle it starts as; `rebuild(true)` at load does that. It costs 25 · 47 · 71 ms at Low · Medium · High on a laptop; on the throttled phone 84 ms at Low (the phone default, paid once at load), 195 ms at Medium and about half a second to a second at High (paid when the visitor presses Detail while paused).- **While paused,** Hangs from, Detail, Reset and a resize show a fresh cloth that has been settled first (`initCloth(paused)`, `rebuild(paused)`); while playing they hang it flat and the loop lets it fall. Shows the points redraws, and Wind, Gravity and Stiffness show at the next Play (they change how it moves).- **Dragging does nothing while paused:** the `if(paused){update();draw();}` line in the `pointermove` handler goes, so a paused cloth stays still.@@ -1301,11 +1308,11 @@ None: leave out the `details.hb-options` block.- **Good for:** Flags and banners · Playful pages · Fashion and textiles · **Avoid on:** Behind text · Serious content- **Prompt:**- > Add a cloth simulation to [the flag, banner or fabric you want to show]. Model the cloth as a grid of points joined to their neighbours by links of fixed length. Each frame, move every point by its own momentum plus gravity and wind, then pull linked points back toward their proper distance a few times over. Pin some points so the cloth hangs, and let the visitor grab and drag the nearest point with the pointer or a finger. Use a coarser grid on phones. If the visitor has reduced motion turned on, show the cloth hanging still. Match the settings listed below.+ > Add a cloth simulation to [the flag, banner or fabric you want to show]. Model the cloth as a grid of points joined to their neighbours by links of fixed length. In fixed 1/60 s steps, as many as the time since the last frame needs, move every point by its own momentum plus gravity and wind, then pull linked points back toward their proper distance a few times over, so the cloth moves at the same speed on every screen. Pin some points so the cloth hangs, and let the visitor grab and drag the nearest point with the pointer or a finger. Use a coarser grid on phones. If the visitor has reduced motion turned on, show the cloth hanging still. Match the settings listed below.- **README What it is:** rewritten:- > A cloth simulation treats fabric as a grid of points joined by links of fixed length. Each frame, every point keeps moving the way it was moving, plus gravity and wind, and then the links pull neighbouring points back into shape. Pin a few points and the grid hangs, sways and folds like fabric, and you can grab it.+ > A cloth simulation treats fabric as a grid of points joined by links of fixed length. Sixty times a second, every point keeps moving the way it was moving, plus gravity and wind, and then the links pull neighbouring points back into shape. Pin a few points and the grid hangs, sways and folds like fabric, and you can grab it.- **README Key parameters:**@@ -1313,7 +1320,7 @@ None: leave out the `details.hb-options` block.|-----------|---------|--------|| Hangs from | Two corners | Pins the top two corners, the whole top edge, one corner, or nothing, in which case the cloth falls to the floor || Wind | Medium | How hard the wind blows; it rises and falls on its own: light is 0.2, medium 0.5 and strong 1.2 |- | Stiffness | Medium | How many times each frame the links are pulled back to length: stretchy is 2, medium 4 and stiff 8 |+ | Stiffness | Medium | How many times each step, sixty a second, the links are pulled back to length: stretchy is 2, medium 4 and stiff 8 || Gravity | Normal | How heavy the cloth is: light is 0.06, normal 0.12 and heavy 0.2 || Detail | Medium | How many points the cloth has: low is 16 × 12, medium 24 × 18 and high 40 × 30; phones start at low || Shows the points | off | Marks every point of the grid, with the pinned ones in red |@@ -1322,10 +1329,11 @@ None: leave out the `details.hb-options` block.- [GPGPU Particle System](../gpgpu-particle-system/) — physics moved to the graphics chip- [Noise-Based Motion](../noise-based-motion/) — natural movement from noise instead of physics- [Canvas Particle Effect](../canvas-particle-effect/) — simpler physics for loose particles-- **README How it works:** unchanged-- **README Production notes:** the Performance bullet becomes "**Performance**: at 40×30 (1,271 points, 2,470 links, 4 passes = 9,880 link corrections a frame) a phone-class CPU manages about 17 frames a second, and 24×18 about 47. The demo starts at 16×12 on phones (screens 600px wide or less, or 500px tall or less), where it holds 60; its Detail setting still lets you pick more." The rest is unchanged.+- **README How it works:** unchanged, except for the frame-rate fix (below): the Verlet lead-in ends "(`dt` is the fixed step, 1/60 s)", and a "**Fixed steps**" paragraph with a `frame(elapsed)` snippet and a paragraph after it follow the constraints snippet.+- **README Production notes:** the Performance bullet becomes "**Performance**: at 40×30 (1,271 points, 2,470 links, 4 passes = 9,880 link corrections a step) a phone-class CPU manages about 17 frames a second (one step and one drawing each), and 24×18 about 47. The demo starts at 16×12 on phones (screens 600px wide or less, or 500px tall or less), where it holds 60; its Detail setting still lets you pick more." The "Verlet vs explicit Euler" bullet says "on every step" in place of "each frame", and a bullet follows it: "**Fixed time step**: one step per drawn frame makes the cloth fall twice as fast on a 120 Hz screen and half as fast on a 30 Hz phone, and stretching a step to the length of the frame changes what Verlet computes. Step by a fixed 1/60 s from an accumulator, as above, and draw once per frame." The rest is unchanged.- **Category line:** `06.15 · 3D & Advanced`- **Pager:** Previous: Image Distortion on Hover (`../image-distortion-hover/`) · Next: Volumetric Smoke / 3D Noise (`../volumetric-smoke/`)+- **Frame-rate fix (wrap-up):** Verlet keeps a point's velocity as the distance it moved in the last step, so every step must be the same length: the loop always steps by `FRAME = 1000/60` and runs as many steps as the time since the last drawn frame calls for. `behind` is the time not yet stepped: `behind += Math.min(dt, 50)`, then `while (behind >= FRAME - 1 && steps < 3) { windT += FRAME; update(); behind -= FRAME; steps++; }` (1 ms of slack, at most 3 steps, so a slow device makes the cloth slower instead of piling up work), and the frame is drawn only if a step ran. The wind clock `windT` adds `FRAME` per step. The 16 ms gate stays, as a cap of 60 drawn frames a second, so a 60 Hz screen runs one step a frame, a 30 Hz screen two, and a 144 Hz screen draws about 48 pictures a second with one or two steps; the cloth falls and swings at the same speed on all of them. `lastT` starts as `null` (the first frame only takes the time), and `resume()` and a `visibilitychange` listener set it to `null` and `behind` to 0. The 120 settle steps in `initCloth(true)` are unchanged. The prompt now says "In fixed 1/60 s steps, as many as the time since the last frame needs" (128 words; the limit is 130).---@@ -1417,7 +1425,7 @@ None: leave out the `details.hb-options` block.- `frame(t)` splits into `step(dt)` and `place()`, and each frame runs both. `step(dt)` only advances `phase` and moves the drop toward the pointer. `place()` works out every drifting circle's position from `phase`, as today's `frame()` does (`b.x = b.bx + Math.sin(phase*b.sx + b.px)*b.ax`, `b.y = b.by + Math.cos(phase*b.sy + b.py)*b.ay`), and writes every circle's `cx`, `cy` and `r` (the drop at its own `x`, `y`).- `start()` returns when `raf` is set; otherwise it forgets the last frame's time, so the first frame after a start adds nothing (today `Math.min(time-last,0.1)` could add a tenth of a second at once), and requests a frame.- **The first picture:** `place()` at load, after `build()`: the circles appear where the first moving frame continues from, so Play never snaps. (`build()` only creates the circles and sets no position or size on them; today's still picture came from `paintStatic()`, which goes.) **While paused,** Number of blobs rebuilds and calls `place()` the same way; Gooeyness shows at once (it is an attribute of the filter); Speed shows at the next Play. The drop's target still follows the pointer, and the drop catches up after Play.-- **Slow motion:** while the switch is on, `phase` adds a third (`dt*speed/3`) and the drop closes 0.03 of the gap each frame in place of 0.09, from the next frame.+- **Slow motion:** while the switch is on, `phase` adds a third (`dt/1000*speed/3`) and the drop closes 0.03 of the gap in every 1/60 s in place of 0.09, from the next frame.- **Reduced motion:** `reduce` goes, with `speed=0` and `paintStatic()`; the `.tip` rule goes with the tip (see the preamble).- **Stage font:** no text on the stage.- **Stage:** the SVG only; the "Move your pointer" tip goes. The stage keeps its radial gradient, `touch-action:none` and `cursor:crosshair`. `:root` gets `--ui-accent:#3fd6c4`; `--accent` and `--accent2` go with the panel, and `--stage` stays (the gradient uses it). `hb-dots`: no (it would replace the gradient). Default height. **The whole blob shows on every stage:** the SVG keeps its drawing coordinates (every formula, and the drop starting at (200, 200)) but becomes `viewBox="20 20 360 360"` with `preserveAspectRatio="xMidYMid meet"`, in place of the full 400 square sliced to fill the stage. Sliced, a stage as wide as the laptop ones showed only a horizontal band of the blob: measured on the page, 57% of each circle's box at 1280×590 (a 958×258 stage), 70% at 1366×657, 77% at 1280×800 and 72% on a sideways phone, and 57% to 71% in the paused first pictures. Now the box is as tall as the stage on a wide stage, and the stage beside it is drawn too. The circles reach at most about 194 units from the middle (about 160 at the extremes of a typical build, and 176 or less in nine builds of ten), so the size of the box is a choice between blob size and cuts. Measured on the page over random builds, phases and 4, 6 and 9 circles: a 300-unit box (`50 50 300 300`) cut some circle in 21% of moments, a 320 box in 7%, a 340 box in 2%, this 360 box in 0.2% to 0.4% (never more than 9% of one circle, a graze) and a 380 box in none, while the blob's size on screen falls only about 5% with each 20 units. The 360 box keeps 99.99% or more of every circle in view on average, on the shared stages and the paused first pictures. The drop is 49 to 83px wide on the shared stages (44px with the full 400 square), and on the phone stage the picture is almost as before (drawing scale 0.828, was 0.8575).@@ -1463,10 +1471,11 @@ None: leave out the `details.hb-options` block.- [Noise-Based Motion](../noise-based-motion/) — smooth noise ripples a blob's outline- [SVG Path Animation](../svg-path-animation/) — lines that draw themselves- [Ray Marching / SDF Scene](../ray-marching-sdf/) — shapes that melt together in 3D-- **README How it works:** unchanged-- **README Production notes:** the Reduced motion bullet becomes: "**Reduced motion.** Under `prefers-reduced-motion: reduce` the demo starts paused, showing the blob still, until the visitor presses Play. In production, never leave an autonomous churning shape running for users who opted out: show one settled arrangement." The rest is unchanged.+- **README How it works:** unchanged, except for the frame-rate fix (below): the `step(dt)` snippet gains `FRAME` and `pull = 1 - Math.pow(1 - 0.09, dt / FRAME)`, the sentence on the integrated phase reads `phase += dt / 1000 * speed`, and a paragraph on the drop's share of the gap follows it.+- **README Production notes:** the Reduced motion bullet becomes: "**Reduced motion.** Under `prefers-reduced-motion: reduce` the demo starts paused, showing the blob still, until the visitor presses Play. In production, never leave an autonomous churning shape running for users who opted out: show one settled arrangement." The frame-rate fix (below) adds a bullet after the two on the filter and Safari: "**Time, not frames**: easing that closes a fixed share of the gap on every frame follows the screen's refresh rate. Scale the share by the time since the last frame, as above, and cap that time (this demo uses 50 ms) so a tab that comes back does not lurch." The rest is unchanged.- **Category line:** `06.17 · 3D & Advanced`- **Pager:** Previous: Volumetric Smoke / 3D Noise (`../volumetric-smoke/`) · Next: 3D Flip Card (`../flip-card-3d/`)+- **Frame-rate fix (wrap-up):** `step(dt)` gets `dt` in milliseconds, at most 50 (it was seconds, at most 0.1): `phase += dt/1000 * speed / (slow ? 3 : 1)`, and the drop closes `pull = 1 - (1 - (slow ? 0.03 : 0.09)) ** (dt / FRAME)` of its gap to the pointer, with `FRAME = 1000/60`. So it closes 0.09 of the gap in every 1/60 s (about 0.17 at 30 Hz and 0.04 at 144 Hz) and arrives in the same time on every screen. The drift phase was already time-based. A `visibilitychange` listener sets the last frame time back to `null`, so the first frame back from a hidden tab adds nothing (as after a start). README: the `step(dt)` snippet, a paragraph on the drop's share and a "Time, not frames" Production note.---