xxxxxxxxxx
36
let points = [];
let t = 0;
const numPoints = 10;
let deltaT;
function setup() {
deltaT = (3 - sqrt(5)) / 2;
createCanvas(400, 400);
background(220);
// Create list of random points to do bezier stuff
for (let ni = 0; ni < numPoints; ni++) {
points.push(createVector(random(0, width), random(0, height)));
}
}
function draw() {
if (t < 1000) {
for (let zz = 0; zz < 100; zz++) {
let pos = createVector(0, 0);
for (let ni = 0; ni < numPoints; ni++) {
let tmp = points[ni].copy();
tmp.mult(binomialCoefficient(numPoints - 1, ni) *
pow(t % 1, ni) *
pow((1 - t % 1), numPoints - 1 - ni));
pos.add(tmp);
}
// pos is now the point of interest
if (t > 0) {
stroke(0, 10);
line(oldPos.x, oldPos.y, pos.x, pos.y);
}
oldPos = pos.copy();
t += deltaT;
}
}
}