Skip to content

Instantly share code, notes, and snippets.

@takumifukasawa
Created June 10, 2020 10:17
Show Gist options
  • Save takumifukasawa/ef1f0361e4fcea8fd2d0048d1059395e to your computer and use it in GitHub Desktop.
Save takumifukasawa/ef1f0361e4fcea8fd2d0048d1059395e to your computer and use it in GitHub Desktop.
ES6: exports for eacheach easing functions
/*
* original is skylerspark's easing functions.
* ref: https://gist.github.com/gre/1650294#gistcomment-3141432
*/
// no easing, no acceleration
export const linear = t => {
return t
}
// accelerating from zero velocity
export const easeInQuad = t => {
return t * t
}
// decelerating to zero velocity
export const easeOutQuad = t => {
return t * (2 - t)
}
// acceleration until halfway, then deceleration
export const easeInOutQuad = t => {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t
}
// accelerating from zero velocity
export const easeInCubic = t => {
return t * t * t
}
// decelerating to zero velocity
export const easeOutCubic = t => {
return --t * t * t + 1
}
// acceleration until halfway, then deceleration
export const easeInOutCubic = t => {
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
}
// accelerating from zero velocity
export const easeInQuart = t => {
return t * t * t * t
}
// decelerating to zero velocity
export const easeOutQuart = t => {
return 1 - --t * t * t * t
}
// acceleration until halfway, then deceleration
export const easeInOutQuart = t => {
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t
}
// accelerating from zero velocity
export const easeInQuint = t => {
return t * t * t * t * t
}
// decelerating to zero velocity
export const easeOutQuint = t => {
return 1 + --t * t * t * t * t
}
// acceleration until halfway, then deceleration
export const easeInOutQuint = t => {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment