xxxxxxxxxx
var shapeSize = 100; // Size of each shape
var gap = 4; // Gap between shapes
var canvasSize = 600; // Canvas size
function setup() {
createCanvas(canvasSize, canvasSize); // Always 600x600 canvas
noLoop(); // Disable continuous drawing
}
function draw() {
background(255); // Set background to white
// Loop through the grid (6 rows and 6 columns)
for (var row = 0; row < 6; row++) {
for (var col = 0; col < 6; col++) {
var x = col * (shapeSize + gap); // Calculate x position
var y = row * (shapeSize + gap); // Calculate y position
drawPattern(x, y, shapeSize); // Draw pattern in each grid cell
}
}
}
// Function to draw a pattern in each square
function drawPattern(x, y, size) {
stroke(0); // Set stroke color to black
fill(255); // Set fill color to white
rect(x, y, size, size); // Draw outer square
// Randomly decide between two patterns
if (random(1) > 0.5) {
fill(0); // Fill left triangle with black
triangle(x, y, x + size, y, x, y + size); // Draw left diagonal triangle
} else {
fill(0); // Fill right triangle with black
triangle(x + size, y, x + size, y + size, x, y + size); // Draw right diagonal triangle
}
}