Skip to content

Instantly share code, notes, and snippets.

@robweychert
Last active August 17, 2026 14:46
Show Gist options
  • Select an option

  • Save robweychert/7efa6a5f762207245646b16f29dd6671 to your computer and use it in GitHub Desktop.

Select an option

Save robweychert/7efa6a5f762207245646b16f29dd6671 to your computer and use it in GitHub Desktop.
Python easing functions

Python easing functions

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 ease_in_out_quad(frame/duration)

linear

image

def linear(t):
    return t

ease_in_sine

image

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

ease_out_sine

image

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

ease_in_out_sine

image

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

ease_in_quad

image

def ease_in_quad(t):
    return t * t

ease_out_quad

image

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

ease_in_out_quad

image

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

image

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

ease_out_cubic

image

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

ease_in_out_cubic

image

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

image

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

ease_out_quart

image

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

ease_in_out_quart

image

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

image

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

ease_out_quint

image

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

ease_in_out_quint

image

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

image

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

ease_out_expo

image

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

ease_in_out_expo

image

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

image

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

ease_out_circ

image

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

ease_in_out_circ

image

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
def linear(t):
return t
def ease_in_sine(t):
return -math.cos(t * math.pi / 2) + 1
def ease_out_sine(t):
return math.sin(t * math.pi / 2)
def ease_in_out_sine(t):
return -(math.cos(math.pi * t) - 1) / 2
def ease_in_quad(t):
return t * t
def ease_out_quad(t):
return -t * (t - 2)
def ease_in_out_quad(t):
t *= 2
if t < 1:
return t * t / 2
else:
t -= 1
return -(t * (t - 2) - 1) / 2
def ease_in_cubic(t):
return t * t * t
def ease_out_cubic(t):
t -= 1
return t * t * t + 1
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
def ease_in_quart(t):
return t * t * t * t
def ease_out_quart(t):
t -= 1
return -(t * t * t * t - 1)
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
def ease_in_quint(t):
return t * t * t * t * t
def ease_out_quint(t):
t -= 1
return t * t * t * t * t + 1
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
def ease_in_expo(t):
return math.pow(2, 10 * (t - 1))
def ease_out_expo(t):
return -math.pow(2, -10 * t) + 1
def ease_in_out_expo(t):
t *= 2
if t < 1:
return math.pow(2, 10 * (t - 1)) / 2
else:
t -= 1
return -math.pow(2, -10 * t) - 1
def ease_in_circ(t):
return 1 - math.sqrt(1 - t * t)
def ease_out_circ(t):
t -= 1
return math.sqrt(1 - t * t)
def ease_in_out_circ(t):
t *= 2
if t < 1:
return -(math.sqrt(1 - t * t) - 1) / 2
else:
t -= 2
return (math.sqrt(1 - t * t) + 1) / 2
@robweychert

Copy link
Copy Markdown
Author

@Enyium Done! I’m a bit of a Python dilettante, so I wasn’t aware that was a naming convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment