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.

fix: Grain / Film Noise Overlay: each new grain frame is due one interval after the last, so the rate matches its caption on any screen

matin5863b0fd9dda
diff --git a/animations/07-ambient-background/grain-overlay/index.html b/animations/07-ambient-background/grain-overlay/index.html
index 41e67eaf..cbf71bc6 100644
--- a/animations/07-ambient-background/grain-overlay/index.html
+++ b/animations/07-ambient-background/grain-overlay/index.html
@@ -298,7 +298,9 @@
// loop() keeps exactly one frame requested in raf; Pause cancels it and Play starts one loop again.
function loop(ts){
raf=requestAnimationFrame(loop);
- if(lastFrame===null||ts-lastFrame>=interval()-SLACK){lastFrame=ts;newGrain()}
+ // each new frame is due one interval after the last was due, so the rate holds on any screen; a long gap starts afresh
+ const iv=interval();
+ if(lastFrame===null||ts-lastFrame>=iv-SLACK){lastFrame=lastFrame===null||ts-lastFrame>=iv*2?ts:lastFrame+iv;newGrain()}
}
function start(){if(raf)return;lastFrame=null;raf=requestAnimationFrame(loop)}