mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-25 09:30:52 +02:00
figured out how to reuse sketches with data-attribute parameters
This commit is contained in:
29
docs/chapters/arclengthapprox/approximate.js
Normal file
29
docs/chapters/arclengthapprox/approximate.js
Normal file
@@ -0,0 +1,29 @@
|
||||
let curve;
|
||||
|
||||
setup() {
|
||||
let 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();
|
||||
|
||||
let alen = 0;
|
||||
const len = curve.length();
|
||||
const LUT = curve.getLUT(this.steps + 1);
|
||||
|
||||
setStroke("red");
|
||||
curve.drawSkeleton(`lightblue`);
|
||||
LUT.forEach((p1,i) => {
|
||||
if (i===0) return;
|
||||
let p0 = LUT[i-1];
|
||||
line(p0.x, p0.y, p1.x, p1.y);
|
||||
alen += dist(p0.x, p0.y, p1.x, p1.y);
|
||||
});
|
||||
|
||||
curve.drawPoints();
|
||||
setFill(`black`);
|
||||
text(`Approximate length, ${this.steps} steps: ${alen.toFixed(2)} (true: ${len.toFixed(2)})`, 10, 15);
|
||||
};
|
Reference in New Issue
Block a user