xxxxxxxxxx
let shiftX = [];
let shiftY = [];
let grid = [];
let gridSize = 20;
let numRows = 22;
let numCols = 12;
function setup() {
createCanvas(numCols * gridSize, numRows * gridSize);
createGrid();
noLoop();
}
function draw() {
background(255);
for (let row = 0; row < numRows; row++) {
for (let col = 0; col < numCols; col++) {
let x = col * gridSize;
let y = row * gridSize;
let angle = grid[row][col];
let xRect = shiftX[row][col];
let yRect = shiftY[row][col];
push();
translate(x + gridSize / 2, y + gridSize / 2);
rotate(radians(angle));
rectMode(CENTER);
stroke(0);
noFill();
rect(xRect, yRect, gridSize, gridSize);
pop();
}
}
}
function createGrid() {
let angle = 0;
let x = 0;
let y = 0;
for (let row = 0; row < numRows; row++) {
let rowAngles = [];
let rowShiftX = [];
let rowShiftY = [];
for (let col = 0; col < numCols; col++) {
rowAngles.push(angle);
angle += random(-5 * row, 5 * row);
rowShiftX.push(x);
x += random(-0.1 * row, 0.1 * row);
rowShiftY.push(y);
y += random(-0.1 * row, 0.1 * row);
}
grid.push(rowAngles);
shiftX.push(rowShiftX);
shiftY.push(rowShiftY);
}
}