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.
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 execution
- 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)
$ npm i
$ npm run build