xxxxxxxxxx
let numLines = 20;
let lineLength = 40;
let patternType = 0;
let lineColor;
function setup() {
createCanvas(600, 600);
noLoop();
lineColor = color(random(255), random(255), random(255));
}
function draw() {
background(255);
randomSeed(0);
for (let i = lineLength / 2; i < width; i += lineLength) {
for (let j = lineLength / 2; j < height; j += lineLength) {
drawLinePattern(i, j);
}
}
}
function drawLinePattern(x, y) {
let choice = (patternType === 0) ? floor(random(4)) : (floor(random(3)) + (patternType + 1)) % 4;
stroke(lineColor);
strokeWeight(3); // strokeWeight
if (choice === 0 || choice === 1) {
line((choice % 2 === 0) ? x : x + lineLength, y, (choice % 2 === 0) ? x + lineLength : x, y + lineLength);
} else {
line(x, (choice % 2 === 0) ? y : y + lineLength, x, (choice % 2 === 0) ? y + lineLength : y);
}
}
function keyPressed() {
if (key === 'r') {
changeLineColorRandomly();
redraw();
} else if (key === 's') {
changeArrangement();
redraw();
}
if(key == 'x') {
save('test.jpg');
}
}
function changeLineColorRandomly() {
lineColor = color(random(255), random(255), random(255));
}
function changeArrangement() {
patternType = (patternType + 1) % 4;
}