1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-22 00:07:10 +02:00

figured out how to reuse sketches with data-attribute parameters

This commit is contained in:
Pomax
2020-08-26 21:56:58 -07:00
93 changed files with 5805 additions and 24390 deletions

View File

@@ -0,0 +1,42 @@
let curve;
setup() {
let type = getParameter(`type`, `quadratic`);
if (type === `quadratic`) {
curve = Bezier.defaultQuadratic(this);
} else {
curve = Bezier.defaultCubic(this);
curve.points[2].x = 210;
}
setMovable(curve.points);
}
draw() {
clear();
curve.drawSkeleton();
curve.drawCurve();
curve.drawPoints();
let minx = Number.MAX_SAFE_INTEGER,
miny = minx,
maxx = Number.MIN_SAFE_INTEGER,
maxy = maxx,
extrema = curve.extrema();
noFill();
setStroke(`red`);
[0, ...extrema.x, ...extrema.y, 1].forEach(t => {
let p = curve.get(t);
if (p.x < minx) minx = p.x;
if (p.x > maxx) maxx = p.x;
if (p.y < miny) miny = p.y;
if (p.y > maxy) maxy = p.y;
if (t > 0 && t< 1) circle(p.x, p.y, 3);
});
setStroke(`#0F0`);
rect(minx, miny, maxx - minx, maxy - miny);
}