XOR grid
Move your mouse over the grid.
Can you clean up the resulting mess?
function setup() {
createCanvas(400, 400);
}
let squares = []
let lastI = 0
function draw() {
background(220);
for (let x = 0; x < 20; x ++) {
for (let y = 0; y < 20; y ++) {
noFill()
rect(x * 20, y * 20, 20, 20)
let i = y * 20 + x
if (squares[i]) {
fill(0)
rect(x * 20 + 2, y * 20 + 2, 16, 16)
}
if (mouseX >= x * 20 && mouseY >= y * 20 && mouseX < x * 20 + 20 && mouseY < y * 20 + 20) {
if (i != lastI) {
squares[i] = !squares[i]
lastI = i
}
}
}
}
}(Originally seen at https://editor.p5js.org/bojidar-bg/sketches/EEE8v1aZw)
Browse more articles?
← Rotating fractal Experiments tagged p5 (19/85) Wall of eyes →
← Drifting car Experiments tagged interactive (6/26) Wall of eyes →
← Rotating fractal Experiments on this site (19/85) Wall of eyes →