xxxxxxxxxx
55
// RECODE
// Padding around the canvas
let padding = 20;
// Size of grid cells (cellSize x cellSize)
let cellSize = 40;
function setup() {
createCanvas(440, 440);
noLoop();
}
function draw() {
background(255);
for (let y = padding; y < height - 2 * padding; y += cellSize) {
for (let x = padding; x < width - 2 * padding; x += cellSize) {
let selectedCell = random([drawCellA,drawCellB,drawCellC,drawCellD]);
selectedCell(x, y);
}
}
}
function drawCellA(x, y) {
push();
translate(x, y);
fill(0);
triangle(0, 0, cellSize, 0, 0, cellSize);
pop();
}
function drawCellB(x, y) {
push();
translate(x, y);
fill(0);
triangle(0, 0, 0, cellSize, cellSize, cellSize);
pop();
}
function drawCellC(x, y) {
push();
translate(x, y);
fill(0);
triangle(0, 0, cellSize, 0, cellSize, cellSize);
pop();
}
function drawCellD(x, y) {
push();
translate(x, y);
fill(0);
triangle(cellSize, 0, cellSize, cellSize, 0, cellSize);
pop();
}