Skip to content

Instantly share code, notes, and snippets.

@AdamSwinden
Created October 9, 2012 12:03
Show Gist options
  • Save AdamSwinden/3858370 to your computer and use it in GitHub Desktop.
Save AdamSwinden/3858370 to your computer and use it in GitHub Desktop.
Animation Curves
// Quadratic
GLfloat QuadraticEaseOut(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
return -end * t*(t-2) + start;
}
GLfloat QuadraticEaseIn(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
return end * t * t + start;
}
GLfloat QuadraticEaseInOut(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
t *= 2;
if (t < 1) return end/2*t*t + start;
t --;
return -end/2 * (t*(t-2) - 1) + start;
}
// Cubic
GLfloat CubicEaseOut(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
t--;
return end*(t*t*t + 1) + start;
}
// Quintic
GLfloat QuinticEaseIn(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
return end*t*t*t*t*t + start;
};
GLfloat QuinticEaseOut(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
t--;
return end*(t*t*t*t*t + 1) + start;
}
GLfloat QuinticEaseInOut(float t, float start, float end) {
if (t < 0.0f) t = 0.0f;
if (t > 1.0f) t = 1.0f;
t *= 2;
if (t < 1) return end/2*t*t*t*t*t + start;
t -= 2;
return end/2*(t*t*t*t*t + 2) + start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment