Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Last active March 1, 2018 12:46
Show Gist options
  • Save tomgidden/911f73634b4abd19cda594b5c458f1db to your computer and use it in GitHub Desktop.
Save tomgidden/911f73634b4abd19cda594b5c458f1db to your computer and use it in GitHub Desktop.
Penner's Easing Equations, cleaned up for modern compiler
/*
Disclaimer for Robert Penner's Easing Equations license:
TERMS OF USE - EASING EQUATIONS
Open source under the BSD License.
Copyright © 2001 Robert Penner
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Easing equation function for a simple linear tweening, with no easing.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeNone (float t, float b, float c, float d)
{
return c*t/d + b;
}
/**
* Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInQuad (float t, float b, float c, float d)
{
float td = t/d;
return c * td * td + b;
}
/**
* Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutQuad (float t, float b, float c, float d)
{
float td = t/d;
return -c *td*(td-2) + b;
}
/**
* Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutQuad (float t, float b, float c, float d)
{
float td2 = t/(d/2);
if (td2 < 1) return c/2*td2*td2 + b;
float td2m = --td2;
return -c/2 * (td2m*(td2m-2) - 1) + b;
}
/**
* Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInQuad (float t, float b, float c, float d)
{
if (t < d/2) return easeOutQuad (t*2, b, c/2, d);
return easeInQuad((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInCubic (float t, float b, float c, float d)
{
float td = t/d;
return c*td*td*td + b;
}
/**
* Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutCubic (float t, float b, float c, float d)
{
float td1 = t/d - 1;
return c*(td1*td1*td1 + 1) + b;
}
/**
* Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutCubic (float t, float b, float c, float d)
{
float td2 = t/(d/2);
if (td2 < 1) return c/2*td2*td2*td2 + b;
float td2m2 = td2-2;
return c/2*(td2m2*td2m2*td2m2 + 2) + b;
}
/**
* Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInCubic (float t, float b, float c, float d)
{
if (t < d/2) return easeOutCubic (t*2, b, c/2, d);
return easeInCubic((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInQuart (float t, float b, float c, float d)
{
float td = t/d;
return c*td*td*td*td + b;
}
/**
* Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutQuart (float t, float b, float c, float d)
{
float td1 = t/d-1;
return -c * (td1*td1*td1*td1 - 1) + b;
}
/**
* Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutQuart (float t, float b, float c, float d)
{
float td2 = t/(d/2);
if (td2 < 1) return c/2*td2*td2*td2*td2 + b;
float td2m2 = td2-2;
return -c/2 * (td2m2*td2m2*td2m2*td2m2 - 2) + b;
}
/**
* Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInQuart (float t, float b, float c, float d)
{
if (t < d/2) return easeOutQuart (t*2, b, c/2, d);
return easeInQuart((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInQuint (float t, float b, float c, float d)
{
float td = t/d;
return c*td*td*td*td*td + b;
}
/**
* Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutQuint (float t, float b, float c, float d)
{
float td1 = t/d-1;
return c*(td1*td1*td1*td1*td1 + 1) + b;
}
/**
* Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutQuint (float t, float b, float c, float d)
{
float td2 = t/(d/2);
if (td2 < 1) return c/2*td2*td2*td2*td2*td2 + b;
float td2m2 = td2 - 2;
return c/2*(td2m2*td2m2*td2m2*td2m2*td2m2 + 2) + b;
}
/**
* Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInQuint (float t, float b, float c, float d)
{
if (t < d/2) return easeOutQuint (t*2, b, c/2, d);
return easeInQuint((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInSine (float t, float b, float c, float d)
{
return -c * cosf(t/d * (M_PI/2.0f)) + c + b;
}
/**
* Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutSine (float t, float b, float c, float d)
{
return c * sinf(t/d * (M_PI/2)) + b;
}
/**
* Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutSine (float t, float b, float c, float d)
{
return -c/2 * (cosf(M_PI*t/d) - 1) + b;
}
/**
* Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInSine (float t, float b, float c, float d)
{
if (t < d/2) return easeOutSine (t*2, b, c/2, d);
return easeInSine((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInExpo (float t, float b, float c, float d)
{
return (t==0) ? b : c * powf(2, 10 * (t/d - 1)) + b - c * 0.001;
}
/**
* Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutExpo (float t, float b, float c, float d)
{
return (t==d) ? b+c : c * 1.001 * (-powf(2, -10 * t/d) + 1) + b;
}
/**
* Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutExpo (float t, float b, float c, float d)
{
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * powf(2, 10 * (t - 1)) + b - c * 0.0005;
return c/2 * 1.0005 * (-powf(2, -10 * --t) + 2) + b;
}
/**
* Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInExpo (float t, float b, float c, float d)
{
if (t < d/2) return easeOutExpo (t*2, b, c/2, d);
return easeInExpo((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInCirc (float t, float b, float c, float d)
{
float td = t/d;
return -c * (sqrtf(1 - (td*td)) - 1) + b;
}
/**
* Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutCirc (float t, float b, float c, float d)
{
float td = t/d-1;
return c * sqrtf(1 - (td*td)) + b;
}
/**
* Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutCirc (float t, float b, float c, float d)
{
float td2 = t/(d/2);
if (td2 < 1) return -c/2 * (sqrtf(1 - td2*td2) - 1) + b;
float td2m2 = td2-2;
return c/2 * (sqrtf(1 - (td2m2*td2m2)) + 1) + b;
}
/**
* Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInCirc (float t, float b, float c, float d)
{
if (t < d/2) return easeOutCirc (t*2, b, c/2, d);
return easeInCirc((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param a Amplitude.
* @param p Period.
* @return The correct value.
*/
static inline float easeInElastic (float t, float b, float c, float d)
{
if (t==0) return b;
float td = t/d;
if (td==1) return b+c;
float p = d*0.3f;
float s, a=0;
if (0 < fabsf(c)) {
a = c;
s = p/4;
} else {
s = p/(2.0f*M_PI) * asinf(c/a);
}
float tdm1 = td-1;
return -(a*powf(2,10*tdm1) * sinf( (tdm1*d-s)*(2*M_PI)/p )) + b;
}
/**
* Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param a Amplitude.
* @param p Period.
* @return The correct value.
*/
static inline float easeOutElastic (float t, float b, float c, float d)
{
if (t==0) return b;
float td = t/d;
if (td==1) return b+c;
float p = d*0.3f;
float s, a=0;
if (0 < fabsf(c)) {
a = c;
s = p/4;
} else {
s = p/(2.0f*M_PI) * asinf(c/a);
}
return (a*powf(2,-10*td) * sinf( (td*d-s)*(2*M_PI)/p ) + c + b);
}
/**
* Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param a Amplitude.
* @param p Period.
* @return The correct value.
*/
static inline float easeInOutElastic (float t, float b, float c, float d)
{
if (t==0) return b;
float td2 = t/(d/2);
if (td2==2) return b+c;
float p = d*0.3f*1.5f;
float s, a=0;
if (0 < fabsf(c)) {
a = c;
s = p/4;
} else {
s = p/(2.0f*M_PI) * asinf(c/a);
}
float td2m1 = td2-1;
if (td2 < 1) return -.5*(a*powf(2,10*td2m1) * sinf( (td2m1*d-s)*(2*M_PI)/p )) + b;
return a*powf(2,-10*td2m1) * sinf( (td2m1*d-s)*(2*M_PI)/p )*.5 + c + b;
}
/**
* Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param a Amplitude.
* @param p Period.
* @return The correct value.
*/
static inline float easeOutInElastic (float t, float b, float c, float d)
{
if (t < d/2) return easeOutElastic (t*2, b, c/2, d);
return easeInElastic((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
* @return The correct value.
*/
static inline float easeInBack (float t, float b, float c, float d)
{
const float s = 1.70158f;
float td = t/d;
return c*td*td*((s+1)*td - s) + b;
}
/**
* Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
* @return The correct value.
*/
static inline float easeOutBack (float t, float b, float c, float d)
{
const float s = 1.70158f;
float td1 = t/d-1;
return c*(td1*td1*((s+1)*td1 + s) + 1) + b;
}
/**
* Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
* @return The correct value.
*/
static inline float easeInOutBack (float t, float b, float c, float d)
{
float s = 1.70158f * 1.525;
float td2 = t/(d/2);
if (td2 < 1) return c/2*(td2*td2*((s+1)*td2 - s)) + b;
float td2m2 = td2-2;
return c/2*(td2m2*td2m2*((s+1)*td2m2 + s) + 2) + b;
}
/**
* Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
* @return The correct value.
*/
static inline float easeOutInBack (float t, float b, float c, float d)
{
if (t < d/2) return easeOutBack (t*2, b, c/2, d);
return easeInBack((t*2)-d, b+c/2, c/2, d);
}
/**
* Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutBounce (float t, float b, float c, float d)
{
float td = t/d;
if (td < (1/2.75)) {
return c*(7.5625*td*td) + b;
} else if (td < (2/2.75)) {
float tdm = td-(1.5/2.75);
return c*(7.5625*tdm*tdm + .75) + b;
} else if (td < (2.5/2.75)) {
float tdm = td-(2.25/2.75);
return c*(7.5625*tdm*tdm + .9375) + b;
} else {
float tdm = td-(2.625/2.75);
return c*(7.5625*tdm*tdm + .984375) + b;
}
}
/**
* Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInBounce (float t, float b, float c, float d)
{
return c - easeOutBounce (d-t, 0, c, d) + b;
}
/**
* Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeInOutBounce (float t, float b, float c, float d)
{
if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b;
else return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
}
/**
* Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
*
* @param t Current time (in frames or seconds).
* @param b Starting value.
* @param c Change needed in value.
* @param d Expected easing duration (in frames or seconds).
* @return The correct value.
*/
static inline float easeOutInBounce (float t, float b, float c, float d)
{
if (t < d/2) return easeOutBounce (t*2, b, c/2, d);
return easeInBounce((t*2)-d, b+c/2, c/2, d);
}
static const float SP_zeta = 0.93;
static const float SP_omega0 = 6.74;
static const float SP_omegaD = 17.391;
static const float SP_A = 0.54;
static const float SP_B = -0.27;
static const float SP_scale = -0.013513;
static const float SP_cutoffY = 0.20236;
static const float SP_cutoffX = 0.91216;
static const float SP_scaleY = 0.26756;
static inline float easeOutSpring(float t, float b, float c, float d)
{
float x = t/d;
float Q = 1-cosf(x*M_PI/2);
float W = (x-SP_cutoffX)/SP_cutoffX;
float Z = expf(-SP_zeta*SP_omega0*W) * (SP_A*cosf(SP_omegaD*W)+SP_B*sinf(SP_omegaD*W));
float xx = (Q<SP_cutoffY) ? Q/SP_scaleY : (1 - Z*SP_scale);
return xx*c + b;
}
static const float easeInExpoBias_bias = 0.3;
static inline float easeInExpoBias (float t, float b, float c, float d)
{
return (t==0) ? b : c * powf(2, 10 * (easeInExpoBias_bias+((1-easeInExpoBias_bias)*t)/d - 1)) + b - c * 0.001;
}
static inline float easeOutSingleBounce (float t, float b, float c, float d)
{
float td = t/d;
float ts = td*td;
float tc = ts*td;
float val = b+c*(-3.7475*tc*ts + 2.0475*ts*ts + 2.7*tc);
return (val>1) ? (2-val) : val;
}
static inline float easeOutTinyBack (float t, float b, float c, float d)
{
float td = t/d;
float ts = td*td;
float tc = ts*td;
float val = b+c*(-3.1975*tc*ts + 3.0975*ts*ts + 1.1*tc);
return val;
//return (val>1) ? (2-val) : val;
}
static inline float easeOutTest (float t, float b, float c, float d)
{
float td = t/d;
float ts = td*td;
float tc = ts*td;
return b+c*(-3.1975*tc*ts + 3.0975*ts*ts + 1.1*tc);
//return b+c*(8.39499999999999*tc*ts + -30.0325*ts*ts + 41.28*tc + -27.09*ts + 8.4475*t);
}
typedef enum {
linear_InOut=0,
quad_In,
quad_Out,
quad_InOut,
quad_OutIn,
cubic_In,
cubic_Out,
cubic_InOut,
cubic_OutIn,
quart_In,
quart_Out,
quart_InOut,
quart_OutIn,
quint_In,
quint_Out,
quint_InOut,
quint_OutIn,
sine_In,
sine_Out,
sine_InOut,
sine_OutIn,
expo_In,
expo_Out,
expo_InOut,
expo_OutIn,
circ_In,
circ_Out,
circ_InOut,
circ_OutIn,
elastic_In,
elastic_Out,
elastic_InOut,
elastic_OutIn,
back_In,
back_Out,
back_InOut,
back_OutIn,
bounce_Out,
bounce_In,
bounce_InOut,
bounce_OutIn,
spring_Out,
expoBias_In,
singleBounce_Out,
tinyBack_Out,
test_Out
} cTransitionType;
static inline float easeByEquation (cTransitionType eqn, float t, float b, float c, float d)
{
switch (eqn) {
case quad_In: return easeInQuad(t,b,c,d); break;
case quad_Out: return easeOutQuad(t,b,c,d); break;
case quad_InOut: return easeInOutQuad(t,b,c,d); break;
case quad_OutIn: return easeOutInQuad(t,b,c,d); break;
case cubic_In: return easeInCubic(t,b,c,d); break;
case cubic_Out: return easeOutCubic(t,b,c,d); break;
case cubic_InOut: return easeInOutCubic(t,b,c,d); break;
case cubic_OutIn: return easeOutInCubic(t,b,c,d); break;
case quart_In: return easeInQuart(t,b,c,d); break;
case quart_Out: return easeOutQuart(t,b,c,d); break;
case quart_InOut: return easeInOutQuart(t,b,c,d); break;
case quart_OutIn: return easeOutInQuart(t,b,c,d); break;
case quint_In: return easeInQuint(t,b,c,d); break;
case quint_Out: return easeOutQuint(t,b,c,d); break;
case quint_InOut: return easeInOutQuint(t,b,c,d); break;
case quint_OutIn: return easeOutInQuint(t,b,c,d); break;
case sine_In: return easeInSine(t,b,c,d); break;
case sine_Out: return easeOutSine(t,b,c,d); break;
case sine_InOut: return easeInOutSine(t,b,c,d); break;
case sine_OutIn: return easeOutInSine(t,b,c,d); break;
case expo_In: return easeInExpo(t,b,c,d); break;
case expo_Out: return easeOutExpo(t,b,c,d); break;
case expo_InOut: return easeInOutExpo(t,b,c,d); break;
case expo_OutIn: return easeOutInExpo(t,b,c,d); break;
case circ_In: return easeInCirc(t,b,c,d); break;
case circ_Out: return easeOutCirc(t,b,c,d); break;
case circ_InOut: return easeInOutCirc(t,b,c,d); break;
case circ_OutIn: return easeOutInCirc(t,b,c,d); break;
case elastic_In: return easeInElastic(t,b,c,d); break;
case elastic_Out: return easeOutElastic(t,b,c,d); break;
case elastic_InOut: return easeInOutElastic(t,b,c,d); break;
case elastic_OutIn: return easeOutInElastic(t,b,c,d); break;
case back_In: return easeInBack(t,b,c,d); break;
case back_Out: return easeOutBack(t,b,c,d); break;
case back_InOut: return easeInOutBack(t,b,c,d); break;
case back_OutIn: return easeOutInBack(t,b,c,d); break;
case bounce_Out: return easeOutBounce(t,b,c,d); break;
case bounce_In: return easeInBounce(t,b,c,d); break;
case bounce_InOut: return easeInOutBounce(t,b,c,d); break;
case bounce_OutIn: return easeOutInBounce(t,b,c,d); break;
case spring_Out: return easeOutSpring(t, 0, 1, 1); break;
case expoBias_In: return easeInExpoBias(t, 0, 1, 1); break;
case singleBounce_Out: return easeOutSingleBounce(t, 0, 1, 1); break;
case tinyBack_Out: return easeOutTinyBack(t, 0, 1, 1); break;
case test_Out: return easeOutTest(t, 0, 1, 1); break;
default: return easeNone(t,b,c,d); break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment