Open jonashw opened 4 years ago
Yeah we should probably add these. Until then, you can do:
import { Tween } from 'paper'
const { PI, sin, cos, sqrt, pow } = Math
// https://github.com/ai/easings.net/tree/master/src/easings/easingsFunctions.ts
Object.assign(Tween.easings, {
easeInSine(x) {
return 1 - cos((x * PI) / 2)
},
easeOutSine(x) {
return sin((x * PI) / 2)
},
easeInOutSine(x) {
return -(cos(PI * x) - 1) / 2
},
easeInExpo(x) {
return x === 0 ? 0 : pow(2, 10 * x - 10)
},
easeOutExpo(x) {
return x === 1 ? 1 : 1 - pow(2, -10 * x)
},
easeInOutExpo(x) {
return x === 0
? 0
: x === 1
? 1
: x < 0.5
? pow(2, 20 * x - 10) / 2
: (2 - pow(2, -20 * x + 10)) / 2
},
easeInCirc(x) {
return 1 - sqrt(1 - pow(x, 2))
},
easeOutCirc(x) {
return sqrt(1 - pow(x - 1, 2))
},
easeInOutCirc(x) {
return x < 0.5
? (1 - sqrt(1 - pow(2 * x, 2))) / 2
: (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2
}
})
I would like to implement easeIn/easeOut/easeInOut variants for sine, exponential, and circular easing functions. Is there any reason they haven't already been implemented?
Current list per the docs: ‘linear’ ‘easeInQuad’ ‘easeOutQuad’ ‘easeInOutQuad’ ‘easeInCubic’ ‘easeOutCubic’ ‘easeInOutCubic’ ‘easeInQuart’ ‘easeOutQuart’ ‘easeInOutQuart’ ‘easeInQuint’ ‘easeOutQuint’ ‘easeInOutQuint’ — default: ‘linear’