-
Custom easing function using expression
My aim is to create keyless position/scale animations using custom easing functions, such as easeInOutExpo and easeOutQuart. I used the script from: https://gist.github.com/creotiv/effdedbe7c5526a493bf, but my current setup only works with easeInOutExpo. When I try to use other easing functions, they don’t produce the expected animation. It seems something is off with my setup. Can you identify what might be causing this problem?
t: current time, b: beginning value, c: change in value, d: duration
/////////1. easeInOutExpo/////////
Math.easeInOutExpo = function (t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t – 1)) + b;
return c/2 * (-Math.pow(2, -10 * –t) + 2) + b;
};
var b = 0;
var c = 800;
var d = 2;
Math.easeInOutExpo(time, b, c, d)
This one works perfectly and you can see from the curve it’s the correct curve of easeInOutExpo. (attachment 1)
/////////2. easeInOutQuart/////////
Math.easeInOutQuart = function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t – 2) + b;
};
var b = 0;
var c = 800;
var d = 2;
Math.easeInOutQuart(time, b, c, d)
This one doesn’t work as the shape does a reversed animation and moves to the direction infinitely after the duration I set. (attachment 2)
/////////3. easeInOutCubic/////////
Math.easeInOutCubic = function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
};
var b = 0;
var c = 800;
var d = 2;
Math.easeInOutCubic(time, b, c, d)
The issue is that the shape repeats the animation and moves in the same direction after its duration.(attachment 3)
I find it confusing that, given the same variables and setup, only the easeInOutExpo function produces the desired movement. Is there a way to create a system where swapping between different easing functions consistently results in the correct animation?