Created
January 8, 2019 15:09
-
-
Save riccardolardi/37fe77eecd26fcd971aecdb13697540f 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 {performance} = require('perf_hooks') | |
let lastTs, newTs | |
const desiredFps = 30.0 | |
const interval = () => { | |
lastTs = newTs | |
newTs = performance.now() | |
const err = newTs - lastTs - 1000.0 / desiredFps | |
const newDelay = 1000.0 / desiredFps - err | |
setTimeout(interval, newDelay) | |
} | |
interval() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment