xxxxxxxxxx
41
let x = 0;
let y = 0;
let spacing = 40;
function setup() {
createCanvas(800, 800);
background(0);
}
function draw() {
stroke(255);
strokeWeight(3);
var r = random(1);
if (r < 1 / 6) {
// Left side of square
line(x, y, x, y + spacing);
} else if (r < 1 / 3) {
// Right side of square
line(x + spacing, y, x + spacing, y + spacing);
} else if (r < 1 / 2) {
// Top side of square
line(x, y, x + spacing, y);
} else if (r < 2 / 3) {
// Bottom side of square
line(x, y + spacing, x + spacing, y + spacing);
} else if (r < 5 / 6) {
// Forward slash
line(x + spacing, y, x, y + spacing);
} else {
// Backward slash
line(x, y, x + spacing, y + spacing);
}
x = x + spacing;
if (x > width) {
x = 0;
y = y + spacing;
}
if (y > width - spacing) {
noLoop();
}
}