This file contains 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
/** | |
* Throttles an animation callback at a specified FPS. | |
* @param {number} The target frame rate. | |
* @param {function} The callback to trigger at the specified FPS. | |
*/ | |
const animate = (fps, fn, startingFrame = 1) => { | |
const fpsInterval = 1000 / fps; | |
let then = window.performance.now(); | |
let now = then; | |
let elapsed = 0; |
This file contains 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
/** | |
* | |
*/ | |
function getScaleTofit(width, height, maxWidth, maxHeight) | |
{ | |
return Math.min(maxWidth / width, maxHeight / height); | |
} | |
/** | |
* |