Skip to content

Instantly share code, notes, and snippets.

@anuraghazra
Last active May 16, 2019 14:34
Show Gist options
  • Save anuraghazra/f97aff1d158bc907d172df6c2e66961b to your computer and use it in GitHub Desktop.
Save anuraghazra/f97aff1d158bc907d172df6c2e66961b to your computer and use it in GitHub Desktop.
const ITERATION = 100; // max physics iterations per frame
function animate() {
ctx.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
// update
for (let i = 0; i < ITERATION; i++) {
for (let d of dots) {
d.constrain();
}
for (let s of sticks) {
s.update();
}
}
for (let d of dots) {
d.update();
d.render(ctx);
}
for (let s of sticks) {
s.update();
s.render(ctx);
}
requestAnimationFrame(animate);
}
animate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment