HomeComputer ScienceFix Your Timestep: JS Animation Loop Simulator

Fix Your Timestep: JS Animation Loop Simulator

Interactive 3D simulator comparing three requestAnimationFrame animation-loop strategies — naive variable dt, clamped variable dt, and a fixed-timestep accumulator — as three balls bounce under the same jittery, dropped-frame conditions real browsers produce.

Computer Science3DModerate60 FPS📱 Mobile-adapted⇄ 2D version
javascript-animations ↗ Open standalone

Every interactive JavaScript animation — a CSS-driven transition, a canvas particle system, a physics-based spring — runs on top of requestAnimationFrame, and the interval between frames is never perfectly constant. This simulator drops three physically identical bouncing balls under the same simulated jittery, dropped-frame conditions, but integrates each one with a different animation-loop strategy: a naive position += velocity * dt update with no safeguards, a clamped-dt version that caps the worst spikes, and a fixed-timestep accumulator that decouples simulation stepping from rendering. Sliders control how severe the frame jitter and FPS throttling are, plus the underlying gravity and bounce restitution, while live readouts track each ball's energy-conservation error against the physically correct fixed-timestep result — making visible exactly why real animation and game loops are built the way they are.

⚙ Under the hood

Compare three requestAnimationFrame animation-loop strategies — naive variable dt, clamped variable dt, and a fixed-timestep accumulator — as three balls bounce under identical simulated jittery, dropped-frame conditions.

javascriptanimationrequestAnimationFramegame-loopphysics-engineweb-development

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)