xxxxxxxxxx
function setup() {
createCanvas(800, 800);
noLoop(); // Draw only one time
strokeWeight(2); // Set line thickness
}
function draw() {
background(25);
let tileSize = 100;
for (let x = 0; x < width; x += tileSize) {
for (let y = 0; y < height; y += tileSize) {
drawLinePattern(x, y, tileSize);
}
}
}
function drawLinePattern(x, y, size) {
let centerX = x + size / 2;
let centerY = y + size / 2;
// Number of lines per tile
let lineCount = random(2, 15);
for (let i = 0; i < lineCount; i++) {
// Random angle for each line
let angle = random(TWO_PI);
// Starting point for the line (in the center of the tile)
let startX = centerX + cos(angle) * size * 0.1;
let startY = centerY + sin(angle) * size * 0.1;
// Ending point for the line (at the edge of the tile)
let endX = centerX + cos(angle) * size * 0.5;
let endY = centerY + sin(angle) * size * 0.5;
// Set a random color for each line
stroke(random(255), random(255), random(255));
// Draw the line
line(startX, startY, endX, endY);
}
}