xxxxxxxxxx
let cols, rows;
let w = 50;
let grid = [];
function setup() {
createCanvas(800, 800);
cols = floor(width / w);
rows = floor(height / w);
for (let j = 0; j < rows; j++) {
for (let i = 0; i < cols; i++) {
grid.push(new Cell(i, j));
}
}
}
function draw() {
background(0, 0, 255);
for (let i = 0; i < grid.length; i++) {
grid[i].show();
}
}
class Cell {
constructor(i, j) {
this.i = i;
this.j = j;
this.topLine = random(1) < 0.5;
this.bottomLine = random(1) < 0.5;
}
show() {
let x = this.i * w;
let y = this.j * w;
stroke(255);
strokeWeight(10);
if (this.topLine) {
line(x, y, x + w, y + w);
}
else if (this.bottomLine) {
line(x, y + w, x + w, y);
}
}
}