xxxxxxxxxx
54
const points = [];
function setup() {
createCanvas(100, 100);
pixelDensity(1);
colorMode(HSB);
points.push(createVector(width/4, height/2, 0));
points.push(createVector(3 * width/4, 3 * width/4, 128));
noLoop();
}
function draw() {
background(220);
noStroke();
for(let i = 0; i < width; i ++) {
for(let j = 0; j < height; j ++) {
let minD = 10000;
let minP = null;
for(let p = 0; p < points.length; p ++) {
let d = dist(points[p].x, points[p].y, i, j);
if(d < minD) {
minD = d;
minP = points[p];
}
}
if(minP) {
fill(minP.z, 128, 128);
rect(i, j, 1, 1);
} else {
console.log("penis");
}
}
}
for(let i = 0; i < points.length; i ++) {
fill(0);
rect(points[i].x, points[i].y, 3, 3);
}
}
function keyReleased() {
addPoint();
}
function addPoint() {
points.push(createVector(random(width), random(height), random([random(20, 100), random(160, 220)])));
draw();
}