xxxxxxxxxx
42
let onOffChance;
let light = [];
function setup() {
createCanvas(610, 610);
// initialize array
for (i = 0; i < (width/30) * (height/30); i++) {
light[i] = 1;
}
console.log(light);
for(var i = 0; i < width/30; i++){
for(var j = 0; j < height/30; j++){
fill(255);
rect(30*i+10, 30*j+10, 20, 20);
}
}
}
function draw() {
background(0);
// slow down the frame rate
frameRate(10);
for(var i = 0; i < width/30; i++){
for(var j = 0; j < height/30; j++){
onOffChance = random(70);
if (onOffChance <= 1 && light[20*i + j] == 1) {
fill(0);
light[20*i + j] = 0;
} else if (light[20*i +j] == 0) {
fill(0);
} else {
fill(255);
}
rect(30*i+10, 30*j+10, 20, 20);
}
}
}