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
fix: Noise-Based Motion moves through the noise by elapsed time, so it runs at the same speed on every screen
matinae1b0f6fcb07
diff --git a/animations/06-3d-advanced/noise-based-motion/README.md b/animations/06-3d-advanced/noise-based-motion/README.mdindex cd08a246..c7c84d38 100644--- a/animations/06-3d-advanced/noise-based-motion/README.md+++ b/animations/06-3d-advanced/noise-based-motion/README.md@@ -30,10 +30,12 @@ function drawWindField() {ctx.stroke();}}- time += speed * 0.01; // advance through noise volume+ time += speed * 0.01 * (dt / FRAME); // advance through noise volume}```+`dt` is the time in milliseconds since the last drawn frame (capped at 50), and `FRAME` is 1000 / 60, the length of one frame on a 60 Hz screen. The noise therefore moves the same distance in a second on a 30, 60 or 144 Hz screen; a fixed `time += speed * 0.01` on every frame would move it twice as fast on a 120 Hz screen and half as fast on a 30 Hz phone.+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.**Blob** — each vertex's radius is offset by noise sampled at its angle:@@ -59,7 +61,7 @@ The noise is read along a circle of radius `48 * SCALE`. A tiny circle would see|-----------|---------|--------|| 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 |@@ -68,6 +70,7 @@ The noise is read along a circle of radius `48 * SCALE`. A tiny circle would see- **Simplex vs Perlin**: Simplex noise (Gustavson 2005) is faster and has fewer directional artifacts than classic Perlin noise. Use Simplex for new projects.- **3D noise for time**: sample noise at `(x, y, time)` in 3D for perfectly seamless temporal animation — the pattern never "resets." 2D noise with time as an offset (as in this demo) is simpler but can have slight discontinuities at the spatial edges.- **`glsl-noise` / `open-simplex-noise`**: for WebGL shaders, include a GLSL noise implementation inline. For JavaScript, `open-simplex-noise` (npm) is the modern standard.+- **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.- **Flow fields**: the wind-field variant is a "flow field" — a classic technique in generative art (Daniel Shiffman's Coding Train). Particles follow the noise field like leaves on a stream.## See alsodiff --git a/animations/06-3d-advanced/noise-based-motion/index.html b/animations/06-3d-advanced/noise-based-motion/index.htmlindex ae51c3a8..75b9f4ae 100644--- a/animations/06-3d-advanced/noise-based-motion/index.html+++ b/animations/06-3d-advanced/noise-based-motion/index.html@@ -250,16 +250,20 @@ function drawBlob(){function frame(){ctx.clearRect(0,0,W,H);if(MODE==='grid')drawGrid();else drawBlob();}-// The loop keeps exactly one pending frame in raf. Each drawn frame moves on through the noise by one step,-// a third of a step while Slow motion is on.+// One step is 1/60 s: the noise moves on by SPD x 0.01 in that time, whatever the screen's refresh rate.+const FRAME=1000/60;+// The loop keeps exactly one pending frame in raf. Each drawn frame moves on through the noise by the time since the last drawn+// one (a gap counts for at most 50 ms), and by a third of that while Slow motion is on. At most one picture is drawn per 16 ms.+// A tab that comes back to the front starts again from its next frame, so the time away adds no step.function loop(ts){raf=requestAnimationFrame(loop);if(last===null){last=ts;return;} // the first frame after a start only takes the time- if(ts-last<16)return;- last=ts;t+=SPD*.01/(slowTog.checked?3:1);+ const dt=ts-last;if(dt<16)return;+ last=ts;t+=SPD*.01*(Math.min(dt,50)/FRAME)/(slowTog.checked?3:1);frame();}function start(){if(raf)return;last=null;raf=requestAnimationFrame(loop);}+document.addEventListener('visibilitychange',()=>{last=null;});// While paused a setting or a resize draws the picture again, so the change shows without anything moving.function redraw(){if(paused)frame();}