Close Date Expand Location Next Open/Close Previous 0.5 of 5 stars 1 of 5 stars 1.5 of 5 stars 2 of 5 stars 2.5 of 5 stars 3 of 5 stars 3.5 of 5 stars 4 of 5 stars 4.5 of 5 stars 5 of 5 stars Repeat Slide Current slide

Python easing functions

For precise programmatic animation

Example usage:

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

linear

def linear(t):
    return t

ease_in_sine

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

ease_out_sine

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

ease_in_out_sine

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

ease_in_quad

def ease_in_quad(t):
    return t * t

ease_out_quad

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

ease_in_out_quad

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

ease_in_cubic

def ease_in_cubic(t):
    return t * t * t

ease_out_cubic

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

ease_in_out_cubic

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

ease_in_quart

def ease_in_quart(t):
    return t * t * t * t

ease_out_quart

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

ease_in_out_quart

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

ease_in_quint

def ease_in_quint(t):
    return t * t * t * t * t

ease_out_quint

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

ease_in_out_quint

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

ease_in_expo

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

ease_out_expo

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

ease_in_out_expo

def ease_in_out_expo(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

ease_in_circ

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

ease_out_circ

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

ease_in_out_circ

def ease_in_out_circ(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