Created
December 17, 2012 21:49
-
-
Save amadeus/4322614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ig.module( | |
'plugins.tween' | |
).requires( | |
'impact.impact' | |
).defines((function(){ 'usestrict'; | |
var Tween = window.Tween = ig.Class.extend({ | |
init: function(options){ | |
// from, to, duration, tween | |
this.from = options.from; | |
this.to = options.to; | |
this.duration = options.duration || 2000; | |
this.tween = options.tween || Tween.TYPES.EASE_IN_OUT_SINE; | |
this.callback = options.callback; | |
this.timer = new ig.Timer(); | |
}, | |
getValue: function(){ | |
var delta = this.timer.delta() * 1000; | |
return delta >= this.duration ? this.to : this.tween( | |
delta, | |
this.from, | |
this.to - this.from, | |
this.duration | |
); | |
} | |
}); | |
Tween.TYPES = { | |
LINEAR: function (t, b, c, d) { | |
return c*t/d + b; | |
}, | |
EASE_IN_SINE: function (t, b, c, d) { | |
return c * (1 - Math.cos(t/d * (Math.PI/2))) + b; | |
}, | |
EASE_OUT_SINE: function (t, b, c, d) { | |
return c * Math.sin(t/d * (Math.PI/2)) + b; | |
}, | |
EASE_IN_OUT_SINE: function (t, b, c, d) { | |
return c/2 * (1 - Math.cos(Math.PI*t/d)) + b; | |
}, | |
EASE_IN_QUAD: function (t, b, c, d) { | |
return c*(t/=d)*t + b; | |
}, | |
EASE_OUT_QUAD: function (t, b, c, d) { | |
return -c * (t/=d)*(t-2) + b; | |
}, | |
EASE_IN_OUT_QUAD: function (t, b, c, d) { | |
if ((t/=d/2) < 1) return c/2*t*t + b; | |
return -c/2 * ((--t)*(t-2) - 1) + b; | |
}, | |
EASE_IN_CIRC: function (t, b, c, d) { | |
return c * (1 - Math.sqrt(1 - (t/=d)*t)) + b; | |
}, | |
EASE_OUT_CIRC: function (t, b, c, d) { | |
return c * Math.sqrt(1 - (t=t/d-1)*t) + b; | |
}, | |
EASE_IN_OUT_CIRC: function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * (1 - Math.sqrt(1 - t*t)) + b; | |
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; | |
}, | |
EASE_IN_EXPO: function (t, b, c, d) { | |
return c * Math.pow(2, 10 * (t/d - 1)) + b; | |
}, | |
EASE_OUT_EXPO: function (t, b, c, d) { | |
return c * (-Math.pow(2, -10 * t/d) + 1) + b; | |
}, | |
EASE_IN_OUT_EXPO: function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * Math.pow(2, 10 * (t - 1)) + b; | |
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; | |
}, | |
EASE_IN_QUINT: function (t, b, c, d) { | |
return c * Math.pow (t/d, 5) + b; | |
}, | |
EASE_OUT_QUINT: function (t, b, c, d) { | |
return c * (Math.pow (t/d-1, 5) + 1) + b; | |
}, | |
EASE_IN_OUT_QUINT: function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * Math.pow (t, 5) + b; | |
return c/2 * (Math.pow (t-2, 5) + 2) + b; | |
}, | |
EASE_IN_QUART: function (t, b, c, d) { | |
return c * Math.pow (t/d, 4) + b; | |
}, | |
EASE_OUT_QUART: function (t, b, c, d) { | |
return -c * (Math.pow (t/d-1, 4) - 1) + b; | |
}, | |
EASE_IN_OUT_QUART: function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * Math.pow (t, 4) + b; | |
return -c/2 * (Math.pow (t-2, 4) - 2) + b; | |
}, | |
EASE_IN_CUBIC: function (t, b, c, d) { | |
return c * Math.pow (t/d, 3) + b; | |
}, | |
EASE_OUT_CUBIC: function (t, b, c, d) { | |
return c * (Math.pow (t/d-1, 3) + 1) + b; | |
}, | |
EASE_IN_OUT_CUBIC: function (t, b, c, d) { | |
if ((t/=d/2) < 1) | |
return c/2 * Math.pow (t, 3) + b; | |
return c/2 * (Math.pow (t-2, 3) + 2) + b; | |
} | |
}; | |
}).bind(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment