Custom Bezier expression not working
/* ---------- Flow Function Declarations ---------- */
function customBezier(t,tMin,tMax,value1,value2,bezierPoints){if(arguments.length!==6)return value;var a=value2-value1;var b=tMax-tMin;var c=clamp((t-tMin)/b,0,1);if(!(bezierPoints instanceof Array)||bezierPoints.length!==4)bezierPoints=[0,0,1,1];return a*h(c,bezierPoints)+value1;function h(f,g){var x=3*g[0];var j=3*(g[2]-g[0])-x;var k=1-x-j;var l=3*g[1];var m=3*(g[3]-g[1])-l;var n=1-l-m;var d=f;for(var i=0;i<5;i++){var z=d*(x+d*(j+d*k))-f;if(Math.abs(z)<1e-3)break;d-=z/(x+d*(2*j+3*k*d));}return d*(l+d*(m+d*n));}}
/* ---------- Flow Function Declarations ---------- */
/* ---------- Flow Expression Template ------------ */
var animationStartTime = 1;
var animationEndTime = 2;
var startValue = value;
var endValue = value * 2;
if (numKeys > 0) {
var nearestKeyIndex = nearestKey(time).index;
if (key(nearestKeyIndex).time > time) nearestKeyIndex--;
if (nearestKeyIndex === 0 || nearestKeyIndex === numKeys) {
startValue = endValue = value;
} else {
animationStartTime = key(nearestKeyIndex).time;
animationEndTime = key(nearestKeyIndex + 1).time;
startValue = key(nearestKeyIndex).value;
endValue = key(nearestKeyIndex + 1).value;
}
}
customBezier(time, animationStartTime, animationEndTime, startValue, endValue, [0, 0.3, 1, 1]); // Nano
/* ---------- Flow Expression Template ------------ */
if (numKeys > 1){
t1 = key(1).time;
t2 = key(2).time;
t3 = key(3).time;
t4 = key(4).time;
v1 = [0, 20];
sliderControl = 2000;
fixedValue = 20;
v2 = [sliderControl, fixedValue];
v3 = [sliderControl, fixedValue];
v4 = [0, 20];
if (time < key(2).time)
customBezier(time, t1, t2, v1, v2);
else customBezier(time, t2, t3, v2, v3);
if (time < key(3).time)
customBezier(time, t1, t2, v1, v2);
else customBezier(time, t3, t4, v3, v4);
} else {
value
}
