Last active
May 16, 2019 14:34
-
-
Save anuraghazra/f97aff1d158bc907d172df6c2e66961b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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