Ease Libraries for Animation
Posted: Tue Mar 15, 2016 10:16 pm
so here's a library I wrote with two files I kept updating for easing with a variety of styles in flash actionscript 2. this can be used for anything, even though most libraries have this now.
ease5.as
easeFormulas.as
code listed below so you can view it online and not have to download it.
ease5.as
easeFormulas.as
ease5.as
easeFormulas.as
code listed below so you can view it online and not have to download it.
ease5.as
Code: Select all
/*
ease5.as ©2009 by Kristoffe Brodeur. All Rights Reserved.
requires easeFormulas.as to function.
#include "./easeFormulas.as" in your code where ./ is the relative path to the file ../ ../../ etc
03-24-2009 complete redo of track system holding ease tracks
03-31-2009 fixed delete bug before easeAction call
04-01-2009 fixed onEnterframe=function(){}; bug where after all tracks were cut off nothing would work
when later called because onEnterFrame wasn't undefined and was simply f(){};
04-07-2009 added # for a number to use with *.useNum(sNum) and prototype *.go() for ready and waiting eases triggered by *.go();
08-11-2009 fixed the possible contflict with 'tgt' as a variable in this function(class) by using '__tgt' and maybe 'tgt' externally
*/
function easeVal(eType,eCF,eTD,eTF,eX1)
{
eVal=0;
//
switch(eType)
{
case ("linear"):
eVal=easeLinear(eCF,eTD,eTF);
break;
case ("inBack"):
eVal=easeInBack(eCF,eTD,eTF,eX1);//overshoot is 4th variable
break;
case ("outBack"):
eVal=easeOutBack(eCF,eTD,eTF,eX1);//overshoot is 4th variable
break;
case ("inQuad"):
eVal=easeInQuad();
break;
case ("outQuad"):
eVal=easeOutQuad();
break;
case ("inoutQuad"):
eVal=easeInOutQuad();
break;
case ("inElastic"):
eVal=easeInElastic();
break;
case ("outElastic"):
eVal=easeOutElastic();
break;
case ("inBounce"):
eVal=easeInBounce(eCF,eTD,eTF);
break;
case ("outBounce"):
eVal=easeOutBounce(eCF,eTD,eTF);
break;
}
//
return eVal;
}
//-----
ease.prototype.go=function()
{
//trace("GO!"+this._track);
this.mc_tracks.easeArr[this._track]._go=true;
}
//-----
function ease(sMC,sTrack,sType,sStagger,sGo,sStart,sDist,sFrames,sX1)
{
//trace("ease> sMC:"+sMC);
this._track=sTrack;
this._mc=sMC;
//trace("eTracks:"+sMC.eTracksMC);
//
if(sMC.eTracksMC.valid!=true)
{
var __tgt=sMC.eTracksMC=sMC.createEmptyMovieClip("eTracksMC1",10000);
this.mc_tracks=__tgt;
__tgt.valid=true;
__tgt.easeArr=new Object();
__tgt.tgt_mc=sMC;
//-----
__tgt.updateTracks=function()
{
this.cnt=0;
//
for(var idx in this.easeArr)
{
this.cnt++;
tgt=this.easeArr[idx];
//
if(tgt._go==true)
{
tgt._cFrame++;
//
if(tgt._cFrame<tgt._frames+1)
{
//-----
val=easeVal(tgt._type,tgt._cFrame,tgt._dist,tgt._frames,tgt._sX1);
//trace(idx);
//
if(idx!="#")
{
this.tgt_mc[tgt._track]=tgt._start+val;
}
//
else
{
this.easeArr[idx]._par_pnt.useNum(tgt._start+val);
}
//
if(tgt._cFrame==tgt._stagger)
{
tgt._par_pnt.staggerAction();
}
}
//
else
{
//delete tgt; doesn't delete what tgt points to! use delete this.easeArr[idx];
x=tgt._par_pnt.easeAction;//reference with var x what function to call
//
if(idx=="#")
{
this._par_pnt.useNum=function(){};
}
delete this.easeArr[idx];//don't delete tgt, because it is only a reference and this.easeArr[idx] will still exist
//
if(x!=undefined)
{
x();//add () to call the referenced function AFTER deleting the array item above so it won't exist in the loop
}
}
}
}
//
if(this.cnt==0){this.onEnterFrame=function(){};}
}
}
x=sMC.eTracksMC.easeArr;
tgtTr=x[sTrack]=new Object();
tgtTr._cFrame=-1;
tgtTr._dist=sDist;
tgtTr._frames=sFrames;
tgtTr._go=sGo;
tgtTr._par_pnt=this;
tgtTr._stagger=sStagger;
tgtTr._sX1=sX1;
tgtTr._start=sStart;
tgtTr._track=sTrack;
tgtTr._type=sType;
//
sMC.eTracksMC.onEnterFrame=function()
{
//trace("*");
this.updateTracks();
}
}
Code: Select all
//easeFormulas.as
//by Kristoffe Brodeur 06-26-2006
//formulas referenced by Robert Penner
//----------
function easeLinear(t,c,d)
{
a2=(c/d)*t;
return a2;
}//f(easeLinear)
//----------
function easeInBack(t,c,d,s)
{
if(s==undefined){s=1.70158;}//if
//default s=1.70158=10% overshoot in radiians
//s=0 no overshoot
t=t/d;
a2=c*t*t*((s+1)*t-s);
return a2;
}//f(easeInBack)
//----------
function easeOutBack(t,c,d,s)
{
if(s==undefined){s=1.70158;}//if
t=t/d-1;
a2=c*(t*t*((s+1)*t+s)+1);
return a2;
}//f(easeOutBack)
//----------
function easeInQuad(t,c,d)
{
t=t/d;
a2=c*t*t;
return a2;
}//f(easeInQuad)
//----------
function easeOutQuad(t,c,d)
{
t=t/d;
a2=-c*t*(t-2);
return a2;
}//f(easeOutQuad)
//----------
function easeInOutQuad(t,c,d)
{
t=t/(d/2);
if(t<1){a2=c/2*t*t;return a2;}//if
else{a2=-c/2*((--t)*(t-2)- 1);return a2;}//else
}//f(easeInOutQuad)
//----------
function easeInElastic(t,c,d,a,p)
{
//from penner if t==0, he has b as the base of your animation start
//i dont use it in the formula, so i return 0, as there is NO b in my formulas
//a2=0 would have been a2=b
//return c would have been return b+c
//if [p]period is 0, nothing really happens
if(t==0){a2=0;return a2;}//if
t=t/d;
if(t==1){a2=c;return a2;}//if
if(!p){p=d*.3;}//if
if(a<Math.abs(c)){a=c;s=p/4;}//if
else{s=p/(2*Math.PI)*Math.asin(c/a);}//else
t--;
a2=-(a*Math.pow(2,10*t)*Math.sin((t*d-s)*(2*Math.PI)/p));
return a2;
}//f(easeInElastic)
//----------
function easeOutElastic(t,c,d,a,p)
{
if(t==0){a2=0;return a2;}//if
t=t/d;
if(t==1){a2=c;return a2;}//if
if(!p){p=d*.3;}//if
if(a<Math.abs(c)){a=c;s=p/4;}//if
else{s=p/(2*Math.PI)*Math.asin(c/a);}//else
a2=a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c;
return a2;
}//f(easeOutElastic)
//----------
function easeInBounce(t,c,d)
{
a2=c-easeOutBounce(d-t,c,d);
return a2;
}//f(easeInBounce)
//----------
function easeOutBounce(t,c,d)
{
t=t/d;
if(t<(1/2.75))
{
a2=c*(7.5625*t*t);return a2;
}
else if(t<(2/2.75))
{
t=t-(1.5/2.75);
a2=c*(7.5625*t*t+.75);return a2;
}
else if(t<(2.5/2.75))
{
t=t-(2.25/2.75);
a2=c*(7.5625*t*t+.9375);return a2;
}
else
{
t=t-(2.625/2.75);
a2=c*(7.5625*t*t+.984375);return a2;
}
}//f(easeOutBounce)