mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-29 11:10:38 +02:00
figured out how to reuse sketches with data-attribute parameters
This commit is contained in:
27
docs/chapters/flattening/flatten.js
Normal file
27
docs/chapters/flattening/flatten.js
Normal file
@@ -0,0 +1,27 @@
|
||||
let curve;
|
||||
|
||||
setup() {
|
||||
const type = getParameter(`type`, `quadratic`);
|
||||
curve = (type === `quadratic`) ? Bezier.defaultQuadratic(this) : Bezier.defaultCubic(this);
|
||||
setMovable(curve.points);
|
||||
setSlider(`.slide-control`, `steps`, (type === `quadratic`) ? 4 : 8);
|
||||
}
|
||||
|
||||
draw() {
|
||||
clear();
|
||||
|
||||
curve.drawSkeleton();
|
||||
|
||||
noFill();
|
||||
start();
|
||||
for(let i=0, e=this.steps; i<=e; i++) {
|
||||
let p = curve.get(i/e);
|
||||
vertex(p.x, p.y);
|
||||
}
|
||||
end();
|
||||
|
||||
curve.drawPoints();
|
||||
|
||||
setFill(`black`);
|
||||
text(`Flattened to ${this.steps} segments`, 10, 15);
|
||||
}
|
Reference in New Issue
Block a user