xxxxxxxxxx
function setup() {
createCanvas(400, 400);
noLoop();
}
function draw() {
background(220); // Light gray background
let tileSize = 40; // Size of each square
let cols = width / tileSize;
let rows = height / tileSize;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
drawPatternTile(x * tileSize, y * tileSize, tileSize);
}
}
}
function drawPatternTile(x, y, size) {
fill(220); // Light gray background for each tile
noStroke();
rect(x, y, size, size);
// Draw each quadrant with a random color
fill(getRandomColor());
rect(x, y, size / 2, size / 2); // Top-left
fill(getRandomColor());
rect(x + size / 2, y, size / 2, size / 2); // Top-right
fill(getRandomColor());
rect(x, y + size / 2, size / 2, size / 2); // Bottom-left
fill(getRandomColor());
rect(x + size / 2, y + size / 2, size / 2, size / 2); // Bottom-right
}
// Returns a random color from a predefined set
function getRandomColor() {
let randIndex = int(random(4));
if (randIndex === 0) return color(255, 0, 0); // Red
if (randIndex === 1) return color(0, 0, 255); // Blue
if (randIndex === 2) return color(255, 255, 0); // Yellow
return color(0, 255, 255); // Cyan
}