xxxxxxxxxx
30
function setup() {
createCanvas(700, 700);
const rows = 100
const cols = 100
const diameter = width/rows;
let counter = 0;
const total = rows * cols;
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
const x = j * width/cols
const y = i * height/rows
const rnd = random()
const colour = rnd > 0.05 ? color("red") : color("black")
if (rnd <= 0.05) counter++
fill(colour)
noStroke()
rect(x , y, diameter, diameter)
}
}
console.log(counter / total)
}