Skip to content

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.

docs: last small fixes in the 3D & Advanced sheet

matinf9f275454873
diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.md
index 42415e74..156d30ca 100644
--- a/docs/superpowers/plans/2026-09-29-3d-content.md
+++ b/docs/superpowers/plans/2026-09-29-3d-content.md
@@ -64,7 +64,7 @@ Four pages: Parallax 3D Tilt, 2.5D / Pseudo-3D, Image Distortion on Hover (step
- The body is `<body class="hb" data-hb-kind="do" data-hb-autoplay>`. Step 1's title and help line are in the section, and every do-it help line ends with ", or press Show me." (a rule for every lane). The player bar holds the Show me button, and the Reset button where the section has one, exactly as in the do-it/scroll plan (Task 2). 3D Flip Card also has Slow motion (css).
- **Show me** runs one example of the interaction, 2.5 to 3 seconds long, and returns the demo to rest. The run keeps one handle (its animation frame or its timer), so a second press restarts it cleanly and anything can stop it.
-- **Stopping a run:** the page listens for `hb:input` at the top level of its inline script. Only if a run is under way (its frame or timer handle is set) does it stop the run, leaving the visitor in control; otherwise it does nothing. A tap sends `hb:input` twice, for `pointerdown` and then for `touchstart`, the second after the page's own `pointerdown` handler has acted, so an unconditional stop would undo what the finger has just done (flatten a card, start fading a distortion). Hovering sends no `hb:input` (the shared script sends it for presses, keys, wheels and touches only), so on the three Hover it pages the page's own `pointermove` handler also ends a run that is under way, for trusted events only (`e.isTrusted`), before it acts on the pointer.
+- **Stopping a run:** the page listens for `hb:input` at the top level of its inline script. Only if a run is under way (its own handle is set: its frame or its timer, or on Image Distortion on Hover its start time, because that page's render loop keeps `raf` set while the pointer rests) does it stop the run, leaving the visitor in control; otherwise it does nothing. A tap sends `hb:input` twice, for `pointerdown` and then for `touchstart`, the second after the page's own `pointerdown` handler has acted, so an unconditional stop would undo what the finger has just done (flatten a card, start fading a distortion). Hovering sends no `hb:input` (the shared script sends it for presses, keys, wheels and touches only), so on the three Hover it pages the page's own `pointermove` handler also ends a run that is under way, for trusted events only (`e.isTrusted`), before it acts on the pointer.
- **Reset** is there only where the demo keeps a state (2.5D / Pseudo-3D's camera, 3D Flip Card's turned card). Parallax 3D Tilt and Image Distortion on Hover return to rest by themselves.
- **Settings** apply at once to what they change (a depth, a colour) and play nothing; the visitor sees them at the next interaction or Show me.
- **Reduced motion:** nothing runs on arrival. Show me, Reset and the visitor's own pointer still work, so CSS rules that would stop them go (Parallax 3D Tilt's `transform:none!important`), while rules that only swap an animation for an instant change stay (3D Flip Card's face fade).
@@ -339,7 +339,11 @@ None: leave out the `details.hb-options` block.
- [3D Model Orbit](../3d-model-orbit/) — a real 3D object drawn with WebGL
- [Hover State Animation](../../04-micro-interactions/hover-state/) — flat hover feedback, without the 3D
- [2.5D / Pseudo-3D](../2-5d-pseudo-3d/) — layers at different depths move with the pointer
-- **README How it works:** unchanged
+- **README How it works:** two edits, so the prose and the snippet match the demo and Key parameters:
+ - "The card's `rotateX`/`rotateY` are computed from cursor position relative to the card's center, normalized to ±maxAngle:" becomes "The card's `rotateX`/`rotateY` are computed from the cursor's position relative to the card's centre, normalized to ±0.5, then scaled by MAX, so the card leans MAX/2 at its edges:".
+ - In the first snippet, `scale(1.03)` becomes `scale(1.04)`, matching the demo and Grows a little.
+
+ The rest is unchanged.
- **README Production notes:** the Reduced motion bullet becomes: "**Reduced motion**: the demo does not tilt on its own, and the card snaps flat when the pointer leaves instead of easing back. In production, keep the card flat for these visitors." The rest is unchanged.
- **Category line:** `06.03 · 3D &amp; Advanced`
- **Pager:** Previous: Scroll-Driven 3D Rotation (`../scroll-driven-3d-rotation/`) · Next: Canvas Particle Effect (`../canvas-particle-effect/`)
@@ -932,7 +936,7 @@ None: leave out the `details.hb-options` block.
- **Description:** Flat layers slide by different amounts, faking depth. Best for hero scenes.
- **Step 1:** Hover it — "Move your pointer across the scene, drag a finger sideways, or press Show me."
- **Player bar:** Show me · Reset. No Slow motion: the camera follows the pointer directly.
-- **Show me:** one run of 3 seconds: the camera sweeps right, back through the middle, left and back, dipping a little, then rests in the middle. For progress p from 0 to 1 and the camera's position when the run starts (`x0 = mx`, `y0 = my`), each animation frame calls `applyParallax(x0*(1-p) + 0.45*Math.sin(2*Math.PI*p), y0*(1-p) + 0.2*Math.sin(Math.PI*p))`. At the end `mx = my = 0`. A second press starts again from where the camera is.
+- **Show me:** one run of 3 seconds: the camera sweeps right, back through the middle, left and back, dipping a little, then rests in the middle. For progress p from 0 to 1 and the camera's position when the run starts (`x0 = mx`, `y0 = my`), each animation frame sets `mx = x0*(1-p) + 0.45*Math.sin(2*Math.PI*p)` and `my = y0*(1-p) + 0.2*Math.sin(Math.PI*p)` and calls `applyParallax(mx, my)`, so `mx` and `my` always hold where the camera is. A second press mid-run, or a run stopped by `hb:input`, therefore starts the next run from where the camera is. At the end `mx = my = 0`.
- **Stopping a run:** on `hb:input`, only if a run is under way (its frame handle is set): cancel the frame, leaving the camera where it is; otherwise do nothing. The stage's `pointermove` handler also ends a run that is under way the same way, for the visitor's own (trusted) events, then moves the camera to the pointer.
- **Reset:** stops a run, sets `mx = my = 0` and calls `applyParallax(0,0)` (today's Reset camera, without the readout).
- **Sequence:** the Mode menu and `autoLoop()` go (Auto-pan becomes Show me). The pointer moves the camera as today (`pointermove` → `applyParallax(mx,my)`), and the camera stays where the pointer leaves it, as today.
@@ -989,7 +993,7 @@ None: leave out the `details.hb-options` block.
- [Parallax 3D Tilt](../parallax-3d-tilt/) — one card leans toward the pointer
- [Scroll-Driven 3D Rotation](../scroll-driven-3d-rotation/) — scrolling moves a 3D object
- **README How it works:** two changes, so the snippets match the demo:
- - The first snippet listens for `pointermove`, as the demo does, and measures the pointer against the stage's box. Its first three lines become:
+ - The first snippet listens for `pointermove`, as the demo does, and measures the pointer against the stage's box. Its first three lines become these four:
```js
stage.addEventListener('pointermove', e => {
@@ -1013,7 +1017,7 @@ None: leave out the `details.hb-options` block.
```
The rest is unchanged.
-- **README Production notes:** unchanged
+- **README Production notes:** in the Scroll-driven variant bullet, "replace `mousemove` with `scroll`" becomes "replace `pointermove` with `scroll`", to match the snippet. The rest is unchanged.
- **Category line:** `06.11 · 3D &amp; Advanced`
- **Pager:** Previous: Chromatic Aberration (`../chromatic-aberration/`) · Next: Ray Marching / SDF Scene (`../ray-marching-sdf/`)
@@ -1166,10 +1170,10 @@ None: leave out the `details.hb-options` block.
- **Description:** The picture ripples and bends around your pointer. Best for portfolio images.
- **Step 1:** Hover it — "Move your pointer over the picture, drag a finger across it, or press Show me."
- **Player bar:** Show me. No Reset: the distortion fades by itself. No Slow motion.
-- **Show me:** one run of 3 seconds: a pretend pointer crosses the picture from left to right along a gentle S, then lets go, and the distortion fades over Fade-out speed. The render loop drives it: while a run is under way, each frame sets `mouseX = W*(0.2 + 0.6*p)` and `mouseY = H*(0.5 + 0.18*Math.sin(2*Math.PI*p))` (backing-store pixels, p from 0 to 1), `active = true` and `amp = 1`; when p reaches 1, `active = false` and the run ends. A second press starts again from the left. Show me wakes the render loop when it has stopped (see Sequence).
-- **Stopping a run:** on `hb:input`, only if a run is under way: end it and set `active = false`; otherwise do nothing, so a tap does not start fading the distortion under a resting finger. The stage's `track()` handler also ends a run that is under way, for the visitor's own (trusted) events, then follows the visitor's pointer as today.
+- **Show me:** one run of 3 seconds: a pretend pointer crosses the picture from left to right along a gentle S, then lets go, and the distortion fades over Fade-out speed. The run's own state is its start time, `demoStart`: `performance.now()` when Show me is pressed, 0 when no run is under way. The render loop drives it: while `demoStart` is set, each frame sets `mouseX = W*(0.2 + 0.6*p)` and `mouseY = H*(0.5 + 0.18*Math.sin(2*Math.PI*p))` (backing-store pixels, p from 0 to 1), `active = true` and `amp = 1`; when p reaches 1, `active = false`, `demoStart = 0` and the run ends. A second press starts again from the left. Show me wakes the render loop when it has stopped (see Sequence).
+- **Stopping a run:** on `hb:input`, only if a run is under way (`demoStart` is set; not `raf`, which the render loop also keeps set while the pointer rests on the picture): set `demoStart = 0` and `active = false`; otherwise do nothing, so a tap does not start fading the distortion under a resting finger. The stage's `track()` handler also ends a run that is under way (`demoStart` set), for the visitor's own (trusted) events, then follows the visitor's pointer as today.
- **Sequence:** `paused`, `poke()` and the Pause button go (a do-it page has no Pause).
- - **The render loop runs only while something moves.** After drawing a frame, `render()` requests the next one only while the pointer is on the picture (`active`), the distortion is still fading (`amp > 0`) or a Show me run is under way; otherwise it sets `raf = null` and stops, so a picture at rest is not redrawn 60 times a second. A frame skipped by today's 15ms gate still requests the next one. `wake()` starts the loop again when it has stopped (it sets `lastT` and `startT` to `performance.now()`, so `phase` does not jump, then requests a frame); `track()` and Show me call it.
+ - **The render loop runs only while something moves.** After drawing a frame, `render()` requests the next one only while the pointer is on the picture (`active`), the distortion is still fading (`amp > 0`) or a Show me run is under way (`demoStart` set); otherwise it sets `raf = null` and stops, so a picture at rest is not redrawn 60 times a second. A frame skipped by today's 15ms gate still requests the next one. `wake()` starts the loop again when it has stopped (it sets `lastT` and `startT` to `performance.now()`, so `phase` does not jump, then requests a frame); `track()` and Show me call it.
- **The first picture:** `draw()` at load. While the loop is stopped, a resize and every setting call `draw()` once (a resize clears the canvas).
- **The picture stands still:** the shader's `uT` stays 0. Today the pattern drifts slowly by itself; a real image would not, and a do-it page moves only when the visitor or Show me moves it.
- `phase` and the fade (`amp`) run as today while the loop runs.