1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-30 19:50:01 +02:00

datasets for sketches

This commit is contained in:
Pomax
2020-08-24 23:20:25 -07:00
parent 4f823cf856
commit 22ffc4b6c2
107 changed files with 5474 additions and 23516 deletions

View File

@@ -0,0 +1,45 @@
setup() {
this.steps = getParameter(`steps`, 10);
}
draw() {
clear();
const w = this.width;
const h = this.height;
const a = h/3;
let trueArea = (4 * a).toFixed(2);
let computedArea = this.drawSlices(w, h, a, this.steps).toFixed(2);
setStroke(`black`);
line(0, h/2, w, h/2);
noFill();
setStroke(`black`);
start();
for(let i=0, f=TAU/w; i<w; i++) {
vertex(i, sin(i*f) * a + h/2);
}
end();
setFill(`black`);
text(`Approximating with ${this.steps} strips: ${computedArea} (true area: ${trueArea}`, w/2, h-10, CENTER);
}
drawSlices(w, h, a, n) {
if (n < 50) setStroke(`white`);
let area = 0;
let step = w/n;
for(let i=0, f=TAU/w, c, y; i<w; i += step) {
c = `rgba(150,150,255,${0.4 + 0.3 * random()}`;
if (n > 50) setStroke(c);
setFill(c);
y = sin((i+step/2) * f) * a;
rect(i, h/2, step, y);
area += abs(step * f * y);
}
return area;
}