frame-interval
Advanced tools
Comparing version 0.0.1 to 0.0.2
module.exports = function(raf) { | ||
return function(fps, tick) { | ||
var delta; | ||
var now; | ||
return function(fps, tick, stop) { | ||
var delta, now; | ||
var then = Date.now(); | ||
@@ -9,4 +8,8 @@ var frame = 0; | ||
stop = stop || function() { return false; }; | ||
function draw() { | ||
raf(function() { | ||
if (stop()) return; | ||
return draw(tick); | ||
@@ -13,0 +16,0 @@ }); |
{ | ||
"name": "frame-interval", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Execute a function n-times per second, on requestAnimationFrame", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# frame-interval | ||
Execute a function n-times per second, on requestAnimationFrame | ||
## Installation | ||
``` | ||
npm i frame-interval --save | ||
``` | ||
## Usage | ||
```javascript | ||
import fps from 'frame-interval'; | ||
const start = fps(requestAnimationFrame)(30, draw); | ||
const FPS = 30; | ||
start(); | ||
fps(requestAnimationFrame)(FPS, frame => { | ||
document.body.innerHTML = `${Math.floor(frame / FPS)} ${frame}`; | ||
})(); | ||
``` | ||
```javascript | ||
let stopped = false; | ||
fps(requestAnimationFrame)(24, () => { | ||
if (someStopCondition) { | ||
stopped = true; | ||
console.log('Logs a single time'); | ||
} else { | ||
console.log('Logs 24 times per-second until someStopCondition is met'); | ||
} | ||
}, () => stopped)(); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2523
61
35