var data = [];
function push(x,y,z) {
data.push({x:x, y:y, z:z});
}
function lerp(a, b, t) {
return a + (b-a)*t;
}
function ifade(t){
return 0.5*t*t*t*t*(t*(2*t-6)+5);
}
function smoothInterp(a, b, t, p1 = 0.5, p2 = 0.5, w1 = 2, w2 = 2) {
// compute the height of the velocity graph, so it will have area of 1 under the curve
// (or alternatively, the slope of the middle middle section of the resulting graph)
const A = (p1 / w1) + (p2 - p1) + ((1.0 - p2)/w2);
const h = 1.0 / A;
if (t < p1) {
return lerp(a,b,Math.pow(t/p1, w1) * p1 * h / w1);
}
else if (t < p2) {
const progress1 = p1 * h / w1;
const progress2 = 1.0 - (1 - p2) * h / w2;
return lerp(a,b,lerp(progress1, progress2, (t - p1) / (p2 - p1)));
}
else {
const rt = 1.0 - t;
const rp = 1.0 - p2;
return lerp(a,b,1.0 - Math.pow(rt/rp, w2) * rp * h / w2);
}
}
function fadeInterp(a, b, t, p1 = 0.5, p2 = 0.5) {
const h = 2.0 / (p2 - p1 + 1.0);
if (t < p1) {
return lerp(a,b,ifade(t/p1) * p1 * h);
}
else if (t < p2) {
const progress1 = p1 * h / 2;
const progress2 = 1.0 - (1 - p2) * h / 2;
return lerp(a,b,lerp(progress1, progress2, (t - p1) / (p2 - p1)));
}
else {
const rt = 1.0 - t;
const rp = 1.0 - p2;
return lerp(a,b,1.0 - ifade(rt/rp) * rp * h);
}
}
for (var a = 0; a <= 1.0; a+=0.01) {
// add up to 10 different results
push (a, smoothInterp(0, -1, a, 0.1, 0.9, 2, 2), "0");
push (a, smoothInterp(0, -1, a, 0.15, 0.15, 1, 1), "1");
push (a, smoothInterp(0, -1, a, 0.15, 0.25, 4, 3), "2");
// push (a, smoothInterp(0, -1, a, 0.15, 0.15, 2, 2), "1");
// push (a, smoothInterp(0, 0.7, a, 0.5, 0.5, 2), "2");
// push (a, fadeInterp(0, 0.7, a, 0.8, 0.8), "3");
}
return data;