Alert Email External Link Info Last.fm Letterboxd 0.5/5 stars 1/5 stars 1.5/5 stars 2/5 stars 2.5/5 stars 3/5 stars 3.5/5 stars 4/5 stars 4.5/5 stars 5/5 stars RSS Source Topic Twitter
I’m redesigning this site in public! Follow the process step by step at v7.robweychert.com.

Python easing functions

For precise programmatic animation

Example usage:

duration = 30
for frame in range(duration):
    return easeInOutQuad(frame/duration)

linear

def linear(t):
    return t

easeInSine

def easeInSine(t):
    import math
    return -math.cos(t * math.pi / 2) + 1

easeOutSine

def easeOutSine(t):
    import math
    return math.sin(t * math.pi / 2)

easeInOutSine

def easeInOutSine(t):
    import math
    return -(math.cos(math.pi * t) - 1) / 2

easeInQuad

def easeInQuad(t):
    return t * t

easeOutQuad

def easeOutQuad(t):
    return -t * (t - 2)

easeInOutQuad

def easeInOutQuad(t):
    t *= 2
    if t < 1:
        return t * t / 2
    else:
        t -= 1
        return -(t * (t - 2) - 1) / 2

easeInCubic

def easeInCubic(t):
    return t * t * t

easeOutCubic

def easeOutCubic(t):
    t -= 1
    return t * t * t + 1

easeInOutCubic

def easeInOutCubic(t):
    t *= 2
    if t < 1:
        return t * t * t / 2
    else:
        t -= 2
        return (t * t * t + 2) / 2

easeInQuart

def easeInQuart(t):
    return t * t * t * t

easeOutQuart

def easeOutQuart(t):
    t -= 1
    return -(t * t * t * t - 1)

easeInOutQuart

def easeInOutQuart(t):
    t *= 2
    if t < 1:
        return t * t * t * t / 2
    else:
        t -= 2
        return -(t * t * t * t - 2) / 2

easeInQuint

def easeInQuint(t):
    return t * t * t * t * t

easeOutQuint

def easeOutQuint(t):
    t -= 1
    return t * t * t * t * t + 1

easeInOutQuint

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

easeInExpo

def easeInExpo(t):
    import math
    return math.pow(2, 10 * (t - 1))

easeOutExpo

def easeOutExpo(t):
    import math
    return -math.pow(2, -10 * t) + 1

easeInOutExpo

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

easeInCirc

def easeInCirc(t):
    import math
    return 1 - math.sqrt(1 - t * t)

easeOutCirc

def easeOutCirc(t):
    import math
    t -= 1
    return math.sqrt(1 - t * t)

easeInOutCirc

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