Skip to content

Instantly share code, notes, and snippets.

@anacampesan
Last active June 27, 2018 21:17
Show Gist options
  • Save anacampesan/4a3fced5a58f3cb66342cf51ab6fd131 to your computer and use it in GitHub Desktop.
Save anacampesan/4a3fced5a58f3cb66342cf51ab6fd131 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
let fps = 15;
let now, then = Date.now();
let first = then;
let interval = 1000 / fps; // 1000ms (1s) / fps
let diff, counter = 0;
(function draw() {
now = Date.now();
diff = now - then;
if (diff > interval) {
counter++;
console.log(counter / ((then-first)/1000));
then = now - (diff % interval);
}
setTimeout(draw, interval);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment