mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-19 15:01:57 +02:00
31 lines
738 B
JavaScript
31 lines
738 B
JavaScript
let curve;
|
|
|
|
setup() {
|
|
const type = this.parameters.type ?? `quadratic`;
|
|
curve = (type === `quadratic`) ? Bezier.defaultQuadratic(this) : Bezier.defaultCubic(this);
|
|
setMovable(curve.points);
|
|
setSlider(`.slide-control`, `steps`, (type === `quadratic`) ? 4 : 8);
|
|
}
|
|
|
|
draw() {
|
|
clear();
|
|
|
|
// draw the curve's polygon, but not the curve itself.
|
|
curve.drawSkeleton();
|
|
|
|
// sample the curve at a few points, and form a polygon with those points
|
|
noFill();
|
|
start();
|
|
for(let i=0, e=this.steps; i<=e; i++) {
|
|
let p = curve.get(i/e);
|
|
vertex(p.x, p.y);
|
|
}
|
|
end();
|
|
|
|
// and for completelion, draw the curve's control points
|
|
curve.drawPoints();
|
|
|
|
setFill(`black`);
|
|
text(`Flattened to ${this.steps} segments`, 10, 15);
|
|
}
|