xxxxxxxxxx
const randArr = [1, 2, 3, 4]
const palette = [
"#aaff00",
"#ffaa00",
"#ff00aa",
"#aa00ff",
"#00aaff"
]
const gapsize = 20
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
noLoop()
}
function draw() {
drawGrid()
}
function drawGrid() {
for (row = 0; row < width; row+=gapsize) {
stroke(random(palette))
for (column = 0; column < height; column+=gapsize) {
drawLines(row, column)
}
}
function drawLines(row, column) {
const r = random(randArr)
strokeWeight(4)
if (r === 1) {
line(row, column, row + gapsize, column + gapsize)
} else if (r === 2) {
line(row + gapsize, column, row, column + gapsize)
} else if (r === 3) {
line(row + (gapsize/2), column, row+(gapsize/2), column + gapsize)
} else if (r === 4) {
line(row, column+(gapsize/2), row+gapsize, column + (gapsize/2))
}
}
}
function keyTyped() {
switch (key) {
case " ":
background(0)
redraw()
}
}