xxxxxxxxxx
// Define the tile size
let tileSize = 40;
function setup() {
createCanvas(400, 400);
background(255);
drawPattern();
}
function drawPattern() {
// Nested loop to create rows and columns of tiles
for (let x = 0; x < width; x += tileSize) {
for (let y = 0; y < height; y += tileSize) {
let choice = random(1);
// Randomly draw lines based on choice
if (choice < 0.25) {
drawLineTLBR(x, y, tileSize);
} else if (choice < 0.5) {
drawLineTRBL(x, y, tileSize);
} else if (choice < 0.75) {
drawLineVertical(x, y, tileSize);
} else {
drawLineHorizontal(x, y, tileSize);
}
}
}
}
// Function to draw diagonal line from top-left to bottom-right
function drawLineTLBR(x, y, size) {
stroke(0);
strokeWeight(random(8, 10));
line(x, y, x + size, y + size);
}
// Function to draw diagonal line from top-right to bottom-left
function drawLineTRBL(x, y, size) {
stroke(0);
strokeWeight(random(8,9));
line(x + size, y, x, y + size);
}
// Function to draw vertical line
function drawLineVertical(x, y, size) {
stroke(0);
strokeWeight(random(9, 10));
line(x + size / 2, y, x + size / 2, y + size);
}
// Function to draw horizontal line
function drawLineHorizontal(x, y, size) {
stroke(0);
strokeWeight(random(10,9));
line(x, y + size / 2, x + size, y + size / 2);
}
function keyPressed() {
// Regenerate pattern on key press
if (key === ' ') {
background(255);
drawPattern();
}
}