xxxxxxxxxx
// Number of tiles
let tileCount = 9;
// Size of each tile
let tileSize;
let margin = 40;
function setup() {
noLoop();
createCanvas(600, 600);
// Calculate tile size
tileSize = width / tileCount;
}
function draw() {
background(250);
// Nested for loops to create tiles
for (let y = 0; y < tileCount; y++) {
for (let x = 0; x < tileCount; x++) {
// Calculate position of each tile
let posX = x * tileSize;
let posY = y * tileSize;
//tile colors
fill(400)
// Draw each tile
rect(posX, posY, tileSize, tileSize);
// Draw random lines inside the tile
drawRandomLines(posX, posY, tileSize);
}
}
}
function drawRandomLines(x, y, size) {
// Draw random lines inside the tile
for (let i = 0; i < 5; i++) {
let startX = x + random(size);
let startY = y + random(size);
let endX = x + random(size);
let endY = y + random(size);
strokeWeight(2);
stroke(0);
line(startX, startY, endX, endY);
}
}
// Function to respond to mouse click
function mousePressed() {
}
// Analyze and write down steps:
// - canvasSize: Size of the canvas (600)
// - gridSize: Size of each grid square (9)
// - Random lines inside each tile with a stroke weight of 2
// - Remove strokes for the grid lines
// - noLoop to ensure the sketch is not continuously redrawn
// - The sketch must be interactive via keyboard or mouse