Last active
October 5, 2020 07:35
-
-
Save aarongeorge/652e1d94687d8d004e1a93b808c064aa to your computer and use it in GitHub Desktop.
A list of easing functions for use with JavaScript and 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
/** | |
* A list of easing functions for use with JavaScript and TypeScript | |
* | |
* Usage: | |
* | |
* `Easings.linear(t)` | |
* Where `t` in a value between 0 and 1 | |
*/ | |
const easeIn = (p: number) => (t: number) => Math.pow(t, p) | |
const easeOut = (p: number) => (t: number) => 1 - easeIn(p)(1 - t) | |
const easeInOut = (p: number) => (t: number) => t < .5 ? easeIn(p)(t * 2) / 2 : easeOut(p)(t * 2 - 1) / 2 + .5 | |
const Easings = { | |
linear: easeIn(1), | |
easeInQuad: easeIn(2), | |
easeOutQuad: easeOut(2), | |
easeInOutQuad: easeInOut(2), | |
easeInCubic: easeIn(3), | |
easeOutCubic: easeOut(3), | |
easeInOutCubic: easeInOut(3), | |
easeInQuart: easeIn(4), | |
easeOutQuart: easeOut(4), | |
easeInOutQuart: easeInOut(4), | |
easeInQuint: easeIn(5), | |
easeOutQuint: easeOut(5), | |
easeInOutQuint: easeInOut(5) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment