Skip to content

Instantly share code, notes, and snippets.

@aarongeorge
Last active October 5, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarongeorge/652e1d94687d8d004e1a93b808c064aa to your computer and use it in GitHub Desktop.
Save aarongeorge/652e1d94687d8d004e1a93b808c064aa to your computer and use it in GitHub Desktop.
A list of easing functions for use with JavaScript and TypeScript
/**
* 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