For precision programmatic animation!
Translated from the JavaScript in Sean Yen’s Easing equations
Illustrations adapted from Andrey Sitnik and Ivan Solovev’s Easings.net
Example usage:
duration = 30
for frame in range(duration):
return easeInOutQuad(frame/duration)
def linear(t):
return t
def easeInSine(t):
import math
return -math.cos(t * math.pi / 2) + 1
def easeOutSine(t):
import math
return math.sin(t * math.pi / 2)
def easeInOutSine(t):
import math
return -(math.cos(math.pi * t) - 1) / 2
def easeInQuad(t):
return t * t
def easeOutQuad(t):
return -t * (t - 2)
def easeInOutQuad(t):
t *= 2
if t < 1:
return t * t / 2
else:
t -= 1
return -(t * (t - 2) - 1) / 2
def easeInCubic(t):
return t * t * t
def easeOutCubic(t):
t -= 1
return t * t * t + 1
def easeInOutCubic(t):
t *= 2
if t < 1:
return t * t * t / 2
else:
t -= 2
return (t * t * t + 2) / 2
def easeInQuart(t):
return t * t * t * t
def easeOutQuart(t):
t -= 1
return -(t * t * t * t - 1)
def easeInOutQuart(t):
t *= 2
if t < 1:
return t * t * t * t / 2
else:
t -= 2
return -(t * t * t * t - 2) / 2
def easeInQuint(t):
return t * t * t * t * t
def easeOutQuint(t):
t -= 1
return t * t * t * t * t + 1
def easeInOutQuint(t):
t *= 2
if t < 1:
return t * t * t * t * t / 2
else:
t -= 2
return (t * t * t * t * t + 2) / 2
def easeInExpo(t):
import math
return math.pow(2, 10 * (t - 1))
def easeOutExpo(t):
import math
return -math.pow(2, -10 * t) + 1
def easeInOutExpo(t):
import math
t *= 2
if t < 1:
return math.pow(2, 10 * (t - 1)) / 2
else:
t -= 1
return -math.pow(2, -10 * t) - 1
def easeInCirc(t):
import math
return 1 - math.sqrt(1 - t * t)
def easeOutCirc(t):
import math
t -= 1
return math.sqrt(1 - t * t)
def easeInOutCirc(t):
import math
t *= 2
if t < 1:
return -(math.sqrt(1 - t * t) - 1) / 2
else:
t -= 2
return (math.sqrt(1 - t * t) + 1) / 2