Handles Animation Timing and Handling for you.
Uses requesAnimationFrame when running on browser side.
Installation
$ npm install animation
Usage
var animation = new Animation({frame:'100ms'});
animation.on('tick', function (dt) { … });
animation.start();
var animation = new Animation({frame:'100ms'});
var animate = function (dt) {
if (process.stdout.write(data)) {
animation.nextTick(animate);
} else {
var t = new Date().getTime()
process.stdout.once('drain', function () {
var now = new Date().getTime();
animate(now - t + dt);
});
}
};
animation.nextTick(animate);
var animation = new Animation();
animation.start();
animation.push(function (dt) {
});
Δt adapters for DOM and jQuery depending on this module to do heavy DOM manipulation like insertion only on requesAnimationFrame.
surrender-cube uses this module to draw a rotating wireframe cube in terminal.
ceilingled uses this to draw images fetched from superfeedr to draw either on SDL or on a LED wall.
Animation
animation = new Animation({
timeoutexecution:'20ms',
execution: '5ms',
timeout: null,
toggle: false,
frame: '16ms'
});
Creates a new Animation controller.
animation.start
animation.start();
Starts animation.
animation.stop
animation.stop();
Stops animation.
animation.pause
animation.pause();
When autotoggle is enabled the Animation pauses itself if the render queue is empty.
animation.resume
animation.resume();
When autotoggle is enabled the Animation resumes itself when the render queue gets filled again after it was emtpy.
animation.nextTick
animation.nextTick(function (dt) { … });
Given callback gets called on next animation tick when running and not paused.
Events
'start'
animation.on('start', function () { … });
Emits start
event every time the animation gets started.
'stop'
animation.on('stop', function () { … });
Emits stop
event every time the animation gets stopped.
'pause'
animation.on('pause', function () { … });
Emits pause
event every time the animation gets paused.
'resume'
animation.on('resume', function () { … });
Emits resume
event every time the animation gets resumed.
'tick'
animation.on('tick', function (dt) { … });
Emits tick
event every time the animation executes a animation tick.
dt
is the time since last animation tick finished.
Use this to do your animation stuff.