Animate a pendulum: Difference between revisions

→‎Within SVG: simplify animate function
(→‎Within SVG: use parenthesis around function statement)
(→‎Within SVG: simplify animate function)
Line 2,423:
var previousTimestamp;
(function animate(timestamp) {
if ( previousTimestamp =!== undefined) {
previousTimestamp = timestamp;
} else {
let dq = rk4((timestamp - previousTimestamp)/1000, q, $ => [$[1], 2*$[1]*$[1]*$[0]/(1+$[0]*$[0]) - $[0]]);
q = [q[0] + dq[0], q[1] + dq[1]];
setPendulumPos(q[0]);
previousTimestamp = timestamp;
}
previousTimestamp = timestamp;
window.requestAnimationFrame(animate);
})()
1,934

edits