Last active
June 27, 2018 21:17
-
-
Save anacampesan/4a3fced5a58f3cb66342cf51ab6fd131 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
<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