Skip to content

Instantly share code, notes, and snippets.

@pbentes
Created March 22, 2025 16:39
Show Gist options
  • Save pbentes/dea1ad6591cd1d397e6ad5a95955ed96 to your computer and use it in GitHub Desktop.
Save pbentes/dea1ad6591cd1d397e6ad5a95955ed96 to your computer and use it in GitHub Desktop.
extends Object
class_name Easings
## Class containing static easing functions.
##
## @tutorial(Easings Website): https://easings.net/
static func ease_in_sine(x: float) -> float:
return 1 - cos((x * PI) / 2)
static func ease_out_sine(x: float) -> float:
return sin((x * PI) / 2)
static func ease_in_out_sine(x: float) -> float:
return -(cos(PI * x) - 1) / 2
static func ease_in_quad(x: float) -> float:
return x * x
static func ease_out_quad(x: float) -> float:
return 1 - (1 - x) * (1 - x)
static func ease_in_out_quad(x: float) -> float:
return 2 * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 2) / 2
static func ease_in_cubic(x: float) -> float:
return x * x * x
static func ease_out_cubic(x: float) -> float:
return 1 - pow(1 - x, 3)
static func ease_in_out_cubic(x: float) -> float:
return 4 * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 3) / 2
static func ease_in_quart(x: float) -> float:
return x * x * x * x
static func ease_out_quart(x: float) -> float:
return 1 - pow(1 - x, 4)
static func ease_in_out_quart(x: float) -> float:
return 8 * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 4) / 2
static func ease_in_quint(x: float) -> float:
return x * x * x * x * x
static func ease_out_quint(x: float) -> float:
return 1 - pow(1 - x, 5)
static func ease_in_out_quint(x: float) -> float:
return 16 * x * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 5) / 2
static func ease_in_expo(x: float) -> float:
return 0 if x == 0 else pow(2, 10 * x - 10)
static func ease_out_expo(x: float) -> float:
return 1 if x == 1 else 1 - pow(2, -10 * x)
static func ease_in_out_expo(x: float) -> float:
if x == 0:
return 0
elif x == 1:
return 1
elif x < 0.5:
return pow(2, 20 * x - 10) / 2
else:
return (2 - pow(2, -20 * x + 10)) / 2
static func ease_in_circ(x: float) -> float:
return 1 - sqrt(1 - pow(x, 2))
static func ease_out_circ(x: float) -> float:
return sqrt(1 - pow(x - 1, 2))
static func ease_in_out_circ(x: float) -> float:
if x < 0.5:
return (1 - sqrt(1 - pow(2 * x, 2))) / 2
else:
return (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2
static func ease_in_back(x: float) -> float:
const c1 = 1.70158
const c3 = c1 + 1
return c3 * x * x * x - c1 * x * x
static func ease_out_back(x: float) -> float:
const c1 = 1.70158
const c3 = c1 + 1
return 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2)
static func ease_in_out_back(x: float) -> float:
const c1 = 1.70158
const c2 = c1 * 1.525;
if x < 0.5:
return (pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
else:
return (pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2
static func ease_in_elastic(x: float) -> float:
const c4 = (2 * PI) / 3;
if x == 0:
return 0
elif x == 1:
return 1
else:
return -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * c4)
static func ease_out_elastic(x: float) -> float:
const c4 = (2 * PI) / 3;
if x == 0:
return 0
elif x == 1:
return 1
else:
return pow(2, -10 * x) * sin((x * 10 - 0.75) * c4) + 1
static func ease_in_out_elastic(x: float) -> float:
const c5 = (2 * PI) / 4.5
if x == 0:
return 0
elif x == 1:
return 1
elif x < 0.5:
return -(pow(2, 20 * x - 10) * sin((20 * x - 11.125) * c5)) / 2
else:
return (pow(2, -20 * x + 10) * sin((20 * x - 11.125) * c5)) / 2 + 1
static func ease_in_bounce(x: float) -> float:
return 1 - ease_out_bounce(1 - x)
static func ease_out_bounce(x: float) -> float:
const n1 = 7.5625;
const d1 = 2.75;
if x < 1 / d1:
return n1 * x * x
elif x < 2 / d1:
x -= 1.5 / d1
return n1 * x * x + 0.75
elif x < 2.5 / d1:
x -= 2.25 / d1
return n1 * x * x + 0.9375
else:
x -= 2.625 / d1
return n1 * x * x + 0.984375
static func ease_in_out_bounce(x: float) -> float:
return (1 - ease_out_bounce(1 - 2 * x)) / 2 if x < 0.5 else (1 + ease_out_bounce(2 * x - 1)) / 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment