xxxxxxxxxx
36
function setup() {
const MARGIN = 10;
createCanvas(400, 400);
const vertices = Array.from({ length: 5 }).map(() => ([
floor(random(width + MARGIN)),
floor(random(height + MARGIN)),
]));
const delaunay = d3.Delaunay.from(vertices);
const bounds = [MARGIN, MARGIN, width - MARGIN, height - MARGIN];
const voronoi = delaunay.voronoi(bounds);
noFill();
background("white");
beginShape();
for (let polygon of voronoi.cellPolygons()) {
for (let v of polygon) {
vertex(v[0], v[1]);
}
}
strokeWeight(10);
stroke("black");
endShape();
noLoop();
}