xxxxxxxxxx
39
// Declare variables for position, speed, and size
let x = 200;
let y = 200;
let speedX = 5;
let speedY = 5;
let r = 50;
function setup() {
createCanvas(500, 400);
}
// Draw the central circle
function draw() {
background("blue");
fill("yellow");
noStroke();
ellipse(x, y, r * 2);
// Draw rotating circles around the central circle
for (let i = 0; i < 8; i++) {
let angle = i * TWO_PI / 8 + frameCount * 0.05;
let offsetX = cos(angle) * 100;
let offsetY = sin(angle) * 100;
let circleX = x + offsetX;
let circleY = y + offsetY;
fill("magenta");
ellipse(circleX, circleY, 30, 30);
}
// Move the central circle
x += speedX;
y += speedY;
// Bounce off the edges
if (x + r > width || x - r < 0) {
speedX *= -1;
}
if (y + r > height || y - r < 0) {
speedY *= -1;
}
}