xxxxxxxxxx
21
function setup() {
createCanvas(windowWidth, windowHeight);
// Draw squares centered on the origin
rectMode(CENTER);
}
function draw() {
background(100);
for (let i = 1; i <= 8; i++) {
// Save the current state (translation/rotation/etc)
push();
// Translate to the origin of the shape
translate(mouseX * i / 8, mouseY * i / 8);
// Rotate around the origin
rotate(millis() / 1000 * PI / 2);
// Because we've translated to the origin, we draw the square at 0, 0
square(0, 0, 50);
// Restore the state saved with push();
pop();
}
}