xxxxxxxxxx
84
let buttonToggle;
let animationRunning = true; // Boolean to track animation state
function setup() {
createCanvas(500, 500);
// Toggle Animation button
buttonToggle = createButton('Stop Animation');
buttonToggle.position(10, height + 10);
buttonToggle.mousePressed(toggleAnimation);
}
function draw() {
background('black');
if (animationRunning) {
fill('orange');
circle(250, 250, 90); // Draw the central orange circle
translate(width / 2, height / 2); // Move origin to the center of the canvas
let r = frameCount / 1000 * PI; // Calculate rotation angle
noStroke();
// Draw and rotate the first shape
rotate(r * 2);
fill('rgb(160,88,0)');
ellipse(200, 180, 40);
// Draw and rotate the second shape
rotate(r * 5);
fill('brown');
ellipse(100, 150, 30);
// Draw and rotate the third shape
rotate(r * 10);
fill('blue');
ellipse(90, 90, 20);
// Draw and rotate the fourth shape
rotate(r * 20);
fill('tan');
ellipse(50, 50, 10);
} else {
// When animation is stopped, draw a static frame
fill('orange');
circle(250, 250, 90); // Draw the central orange circle
translate(width / 2, height / 2); // Move origin to the center of the canvas
let r = PI; // Static rotation angle for the stopped frame
noStroke();
// Draw and rotate the first shape
rotate(r * 2);
fill('rgb(160,88,0)');
ellipse(200, 180, 40);
// Draw and rotate the second shape
rotate(r * 5);
fill('brown');
ellipse(100, 150, 30);
// Draw and rotate the third shape
rotate(r * 10);
fill('blue');
ellipse(90, 90, 20);
// Draw and rotate the fourth shape
rotate(r * 20);
fill('tan');
ellipse(50, 50, 10);
}
}
function toggleAnimation() {
animationRunning = !animationRunning; // Toggle the animation state
// Update the button text based on the animation state
if (animationRunning) {
buttonToggle.html('Stop Animation');
} else {
buttonToggle.html('Start Animation');
}
}