let segments, currentX, currentY, segmentCount, direction, collectionCount, collections, recH, recW, backgroundGrid;
let directions=['up','down','left','right'];
let segmentColors = ['#3333AC','#AA0808','#6808AA','#22B900','#00A5A2','#BF8B00',"#C20064"];
createCanvas(width, height);
backgroundGrid = random([4,8,16,32,64]);
line(currentX,0,currentX,width);
currentX = currentX+width/backgroundGrid;
line(0,currentY,height,currentY);
currentY = currentY+height/backgroundGrid;
stroke(segmentColors[int(random(0,segmentColors.length))]);
strokeWeight(random([1,2,3]));
segments = int(random(1000,2000));
fill(segmentColors[int(random(0,segmentColors.length))]);
recH = random(height/40,height/10);
recW = random(recH/8,recH/4);
console.log("recH " + round(recH,2));
console.log("recW " + round(recW,2));
console.log("segments " + segments)
while(segmentCount<segments){
direction = directions[int(random(0,directions.length))];
if(currentX+recH>width){ continue; }
rect(currentX,currentY,recH,recW,recW,recW);
currentX = currentX+recH-recW;
else if(direction=='down')
if(currentY+recH>height){ continue; }
rect(currentX,currentY,recW,recH,recW,recW);
currentY = currentY+recH-recW;
if(currentY-recH<0){ continue; }
rect(currentX,currentY-recH+recW,recW,recH,recW,recW);
currentY = currentY-recH+recW;
else if(direction=='left')
if(currentX-recH<0){ continue; }
rect(currentX-recH+recW,currentY,recH,recW,recW,recW);
currentX = currentX-recH+recW;
segmentCount=segmentCount+1;