xxxxxxxxxx
28
let colNum = 50;
let rowNum = 50;
let colW, rowH;
function setup() {
createCanvas(800, 800);
colW = width / colNum;
rowH = height / rowNum;
}
function draw() {
background(200);
for (let col = 0; col <= colNum; col++) {
for (let row = 0; row <= rowNum; row++) {
let x = col * colW;
let y = row * rowH;
let d = dist(mouseX, mouseY, x, y);
d = map(d, 0, dist(0, 0, width, height) / 2, 0, 200);
b = map(d, 0, dist(0, 0, width, height) / 2, 255, 0);
if ((col % 2 == 1 && row % 2 == 1) || (col % 2 == 0 && row % 2 == 0)) {
fill(20, d);
} else {
fill(255, b);
}
rect(x, y, colW, rowH);
}
}
}