//Sinusoidal easing //Jeff Thompson | 2019/20 | jeffreythompson.org let SINUSOIDAL = 5; // when the easing is applied (start, end, or both) let IN = 0; let OUT = 1; let BOTH = 2; // a map() replacement that allows for specifying easing curves // with arbitrary exponents function map2(value, start1, stop1, start2, stop2, type, when) { let b = start2; let c = stop2 - start2; let t = value - start1; let d = stop1 - start1; let p = 0.5; switch (type) { case SINUSOIDAL: if (when === IN) { return -c * Math.cos(t/d * (Math.PI/2)) + c + b; } else if (when === OUT) { return c * Math.sin(t/d * (Math.PI/2)) + b; } else if (when === BOTH) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; } break; }; return 0; }