◤ phase space (x, v)◣ position vs time

Integrator Stability Under Frame Jitter — Phase-Space Simulator (2D)

This is the 2D companion to the "Fix Your Timestep" 3D simulator, and it isolates a different half of the same real problem: not just how an animation loop handles a jittery requestAnimationFrame clock, but how the choice of numerical integrator interacts with it. A single ideal mass-spring oscillator (x'' = -ω²x, whose exact energy never changes) is stepped forward three independent ways under the identical jittered frame-time stream — naive explicit Euler with no safeguard, a clamped semi-implicit (symplectic) Euler, and a fixed-timestep RK4 accumulator — and each one's trajectory is drawn live as a phase-space portrait (position vs. velocity) alongside a scrolling position-vs-time strip chart. Sliders control frame jitter severity, the simulated FPS cap, the oscillator's stiffness, and its starting amplitude, while live readouts track each integrator's energy-conservation error against the exact analytic solution — making visible why explicit Euler's orbit spirals outward forever, why symplectic Euler stays on a closed loop, and why decoupling physics steps from rendering with RK4 all but eliminates the error.