q5#js
A small and fast alternative implementation of p5.js. [Download (33KB minified)]
bezierTangent I
q5.js(this)
p5.js(reference)
new Q5("global");
noFill();
bezier(85, 20, 10, 10, 90, 90, 15, 80);
let steps = 6;
fill(255);
for (let i = 0; i <= steps; i++) {
let t = i / steps;
// Get the location of the point
let x = bezierPoint(85, 10, 90, 15, t);
let y = bezierPoint(20, 10, 90, 80, t);
// Get the tangent points
let tx = bezierTangent(85, 10, 90, 15, t);
let ty = bezierTangent(20, 10, 90, 80, t);
// Calculate an angle from the tangent points
let a = atan2(ty, tx);
a += PI;
stroke(255, 102, 0);
line(x, y, cos(a) * 30 + x, sin(a) * 30 + y);
// The following line of code makes a line
// inverse of the above line
//line(x, y, cos(a)*-30 + x, sin(a)*-30 + y);
stroke(0);
ellipse(x, y, 5, 5);
}
From the original p5 example at https://p5js.org/reference/#/p5/bezierTangent