xxxxxxxxxx
let side, spacing, margin;
function setup() {
createCanvas(windowWidth, windowHeight);
side = min(width, height);
spacing = side / 12;
margin = {
x: (width - side) / 2,
y: (height - side) / 2
}
noLoop();
}
function drawLine(x, y, spacing) {
stroke("#050505");
fill("#fffbe6");
switch (floor(random(4))) {
case 0:
line(x, y, x + spacing, y + spacing);
break;
case 1:
line(x + spacing, y, x, y + spacing);
break;
case 2:
line(x, y, x + spacing, y);
break;
case 3:
line(x, y, x, y + spacing);
break;
}
}
function drawShape(x, y) {
const palette = [
'#D64933',
'#FA8334',
'#EA9010',
'#2D854A',
'#14591D',
'#3587A4',
'#23B5D3',
'#70587C',
'#573280',
'#832232',
'#DA4167',
'#E87461'
];
rectMode(CENTER);
const color = random(palette);
stroke(color);
switch (floor(random(2))) {
case 0:
circle(x, y, 10);
break;
case 1:
square(x, y, 10);
break;
}
}
function drawRow(y, spacing) {
for (let x = spacing; x <= side - spacing; x += spacing) {
if (x + spacing <= side - spacing &&
y + spacing <= side - spacing) {
drawLine(x, y, spacing);
}
drawShape(x, y);
}
}
function draw() {
background("#fffbe6");
translate(margin.x, margin.y)
strokeWeight(4);
for (let y = spacing; y <= side - spacing; y += spacing) {
drawRow(y, spacing);
}
}
function mouseClicked() {
setup();
draw();
}