xxxxxxxxxx
function setup() {
createCanvas(800, 800);
background(255);
}
function draw() {
noLoop();
let numOfParts = 6;
let partWidth = width / numOfParts;
for (let i = 0; i < numOfParts; i++) {
drawLines(i * partWidth, 0, (i + 1) * partWidth, height, i % 4);
drawLines(i * partWidth, 0, (i + 1) * partWidth, height, (i + 1) % 4);
}
}
function drawLines(x1, y1, x2, y2, lineDirection) {
let lineDensity = 25;
stroke(0);
switch (lineDirection) {
case 0: // Top-left to bottom-right diagonal lines
for (let i = x1; i <= x2; i += lineDensity) {
line(i, y1, i + lineDensity, y2);
}
break;
case 1: // Top-right to bottom-left diagonal lines
for (let i = x1; i <= x2; i += lineDensity) {
line(i + lineDensity, y1, i, y2);
}
break;
case 2: // Vertical lines
for (let i = x1; i <= x2; i += lineDensity) {
line(i, y1, i, y2);
}
break;
case 3: // Horizontal lines
for (let i = y1; i <= y2; i += lineDensity) {
line(x1, i, x2, i);
}
break;
}
}