Last active
May 23, 2021 10:18
-
-
Save yukulele/2234731c0445dd5b1f4673889bf3330c to your computer and use it in GitHub Desktop.
Simple Easing Functions in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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