node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

tween-array

tween-array

stable

A tween object for tweenr which interpolates single-dimensional arrays.

var ticker = require('tween-ticker')()
var array = require('tween-array')
 
var start = [0, 0],
    end = [10, 4]
 
//push a tween object onto the stack 
ticker.push( array(start, end, { duration: 1, delay: 1 }) )
 
//step the ticker 
ticker.tick(0.5)
 
console.log(start) // -> [5, 2] 

memory optimization

This is generally faster than object tweening and leads to less garbage. If you specify a start parameter you can avoid creating any garbage, aside from the tween itself.

var start = [50, 50], end = [100, 100], tmp = [0, 0]
var tween = array(tmp, end, { duration: 3, start: start })
tween.tick(3)
 
console.log(start) // -> [50, 50] 
console.log(tmp)   // -> [100, 100] 

Usage

NPM

tween = array(target, end[, opt])

Creates a new array tween that can be ticked by tween-ticker or your engine of choice. This will tween the target array to end. Options are the same as ticker.to(), additionally:

  • start can be an array to use as the start values

If opt is a number, it is assumed to be a duration.

//equivalent 
array(start, end, { duration: 1 })
array(start, end, 1)

License

MIT, see LICENSE.md for details.