Skip to content

Instantly share code, notes, and snippets.

@yukulele
Last active May 23, 2021 10:18
Show Gist options
  • Save yukulele/2234731c0445dd5b1f4673889bf3330c to your computer and use it in GitHub Desktop.
Save yukulele/2234731c0445dd5b1f4673889bf3330c to your computer and use it in GitHub Desktop.
Simple Easing Functions in Typescript
class Ease {
static in(t: number, p = 1) {
return t ** p
}
static out(t: number, p = 1) {
return 1 - Ease.in(1 - t, p)
}
static inOut(t: number, p = 1):number {
if (t <= 0.5) {
return Ease.in(t * 2, p) / 2
}
return 1 - Ease.inOut(1 - t, p)
}
}
Ease.in(t) // linear(t)
Ease.in(t, 2) // easeInQuad(t)
Ease.out(t, 3) // easeOutCubic(t)
Ease.inOut(t, 5) // easeInOutQuint(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment