xxxxxxxxxx
32
let width = 400
let height = 400
let margin = 50
let numRows = 10
let numCols = 10
let squareLength = (width -2 * margin) / numCols
let maxShift = squareLength /6
function setup() {
createCanvas(400, 400);
frameRate(1);
}
function draw() {
background(220);
noFill();
for (let row = 0; row < numRows; row += 1) {
drawRow(row);
}
}
function drawRow(row) {
for (let column = 0; column < numCols; column += 1) {
let x = margin + column*squareLength + random(maxShift)
let y = margin + row*squareLength + random(maxShift)
rect(x,y, squareLength, squareLength);
}
}