I found a good site containing an implementation in different languages: Robert Penner Weakening functions
For example, Elastic easing C ++ code:
float Elastic::easeIn (float t,float b , float c, float d) { if (t==0) return b; if ((t/=d)==1) return b+c; float p=d*.3f; float a=c; float s=p/4; float postFix =a*pow(2,10*(t-=1)); // this is a fix, again, with post-increment operators return -(postFix * sin((t*ds)*(2*PI)/p )) + b; } float Elastic::easeOut(float t,float b , float c, float d) { if (t==0) return b; if ((t/=d)==1) return b+c; float p=d*.3f; float a=c; float s=p/4; return (a*pow(2,-10*t) * sin( (t*ds)*(2*PI)/p ) + c + b); } float Elastic::easeInOut(float t,float b , float c, float d) { if (t==0) return b; if ((t/=d/2)==2) return b+c; float p=d*(.3f*1.5f); float a=c; float s=p/4; if (t < 1) { float postFix =a*pow(2,10*(t-=1)); // postIncrement is evil return -.5f*(postFix* sin( (t*ds)*(2*PI)/p )) + b; } float postFix = a*pow(2,-10*(t-=1)); // postIncrement is evil return postFix * sin( (t*ds)*(2*PI)/p )*.5f + c + b; }
source share