Calculates cubic Bezier curve values
by sperske
JavaScript
// adapted from https://morethandev.hashnode.dev/demystifying-the-cubic-bezier-function-ft-javascript
function bezier(initial, p1, p2, final) {
return (t) =>
(1 - t) * (1 - t) * (1 - t) * initial +
3 * (1 - t) * (1 - t) * t * p1 +
3 * (1 - t) * t * t * p2 +
t * t * t * final
}
// timing demo found in https://cubic-bezier.com/#0,1.1,.45,1
const peppy = bezier(0, 1.1, 0.45, 1)
for (let s = 0; s <= 100; s++) {
console.log(s, s / 100 , peppy(s / 100))
}