xxxxxxxxxx
82
let cells = [];
const cellSize = 2;
let currentRow = -300;
function setup() {
createCanvas(600, 600);
// background('black');
background('white');
strokeWeight(0.02);
const numCells = (width / cellSize);
for (let i = 0; i < numCells; i++) {
cells[i] = round(random(0,1));
}
cells[round(numCells / 2)] = 1;
}
function draw() {
// fill('white');
noStroke();
translate(0, currentRow*cellSize);
currentRow++;
for (let i = 0; i < cells.length; i++) {
if (cells[i] == 0) {
// fill('white');
fill('black');
// noFill();
// stroke('black');
push();
translate(50, round(random(0,5)));
for (j = 0; j < 8; j++) {
rotate(PI*j/5);
ellipse(i * cellSize, 0, cellSize*2, cellSize/2);
}
pop();
} else {
// fill('black');
fill('white');
// noStroke();
// stroke('white');
push();
translate(50, 50);
for (j = 0; j < 8; j++) {
rotate(PI*j/5);
rect(i * cellSize, 0, cellSize/3, cellSize*3);
}
pop();
}
}
let newCells = [];
for (let i = 0; i < cells.length; i++) {
const leftleft = cells[i - 2] ?? 0;
const left = cells[i - 1] ?? 0;
const middle = cells[i];
const right = cells[i + 1] ?? 0;
const rightright = cells[i + 2] ?? 0;
const sum = leftleft+ left + middle + right+ rightright;
if (sum ==0 || sum %5 ){
newCells[i] = 1;
} else {
newCells[i] = 0;
}
}
cells = newCells;
}