Gods Game
https://gyazo.com/d58b70f9a779a4ba845b5812211ec0cb
code:GodsGame.js
const cols = 50;
const rows = 50;
let boxes;
function setup() {
createCanvas(400, 400);
frameRate(6);
boxes = [];
for (var y = 0; y < rows; y++) {
let boxRow = []
for (var x = 0; x < cols; x++) {
const box = createCheckbox();
box.position(x * 14, y * 14);
box.checked(random() >= 0.9)
boxRow.push(box);
}
boxes.push(boxRow);
}
}
function draw() {
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
boxesyx.checked(justifyCell(x, y)); }
}
}
function justifyCell(x, y) {
let sum = 0;
if (y > 0) {
if (x > 0) {
if (boxesy-1x-1.checked()) sum += 1; }
if (boxesy-1x .checked()) sum += 1; if (x < cols-1) {
if (boxesy-1x+1.checked()) sum += 1; }
}
if (x > 0) {
if (boxesy x-1.checked()) sum += 1; }
if (x < cols-1) {
if (boxesy x+1.checked()) sum += 1; }
if (y < rows-1) {
if (x > 0) {
if (boxesy+1x-1.checked()) sum += 1; }
if (boxesy+1x .checked()) sum += 1; if (x < cols-1) {
if (boxesy+1x+1.checked()) sum += 1; }
}
if (sum >= 2 && sum < 4) {
return true;
} else {
return false;
}
} else {
if (sum == 3) {
return true;
} else {
return false;
}
}
}