fps-run-js
v1.1.0
Published
A JavaScript utility class that enables fps-throttled function execution.
Readme
fps-run-js
A JavaScript utility class that enables fps-throttled function
execution. Internally, requestAnimationFrame() is arranged to execute
a user-provided function at a specified fps. The code is based on this
Stack Overflow
discussion
and its related JSFiddle demo. Node.js
support was added using setImmediate() instead of
requestAnimationFrame().
The module is compiled as a UMD (Universal Module Definition) module. So it can be consumed by script-tags, AMD loading (require.js), and Node.js.
Usage
npm install fps-run-js, load fps-run.js and in code:
fr = new FpsRun(); // create a runner
fr.start(f, 5); // execute function f() at 5 fps
//...
fr.stop(); // stop executionLive Demos 🔥
- demo-logging: Executing a function at 5 fps for 4 seconds (index.html)
- demo-threejs: Rendering 3D graphics at 20 fps for 8 seconds using three.js (index.html)
- demo-comp: Rendering rotating cubes at 5, 10, and 20 fps, respectively (index.html)
Build
$ npm install # set up build tools
$ npm run build