xxxxxxxxxx
function setup() {
createCanvas(400, 400); // Canvas size
background(255); // White background
stroke(0); // Black line color
// Define variables for grid and drawing probability
let gridSize = 50; // Grid cell size
let drawChance = 0.4; // 40% probability to draw in each cell
// Loop through grid based on gridSize
for (let y = 0; y < height; y += gridSize) {
for (let x = 0; x < width; x += gridSize) {
if (random(1) < drawChance) { // Only draw if random condition is met
let choice = int(random(5)); // Randomly pick one of 5 cases
// Draw specific shapes based on random choice
if (choice == 0) {
// Full horizontal line
line(x, y + gridSize / 2, x + gridSize, y + gridSize / 2);
} else if (choice == 1) {
// Full vertical line
line(x + gridSize / 2, y, x + gridSize / 2, y + gridSize);
} else if (choice == 2) {
// Plus symbol (+)
line(x + gridSize / 2, y, x + gridSize / 2, y + gridSize); // Vertical part of plus
line(x, y + gridSize / 2, x + gridSize, y + gridSize / 2); // Horizontal part of plus
} else if (choice == 3) {
// Mini horizontal line (shorter)
let miniLength = gridSize / 3;
line(x + (gridSize - miniLength) / 2, y + gridSize / 2, x + (gridSize + miniLength) / 2, y + gridSize / 2);
} else if (choice == 4) {
// Mini vertical line (shorter)
let miniLength = gridSize / 3;
line(x + gridSize / 2, y + (gridSize - miniLength) / 2, x + gridSize / 2, y + (gridSize + miniLength) / 2);
}
}
}
}
}