xxxxxxxxxx
47
let centerX, centerY;
let circleRadius = 30;
let rotationAngle = 0;
let rotationSpeed = 1;
let isClockwise = true;
function setup() {
createCanvas(400, 400);
centerX = width / 2;
centerY = height / 2;
}
function draw() {
background(64, 50, 60); // Dark purple background
// Draw the spinning CD
fill(220);
stroke(255);
ellipse(centerX, centerY, circleRadius * 2);
// Draw lines representing music notes
for (let angle = 0; angle < 360; angle += 4) {
let x1 = centerX + cos(radians(angle + rotationAngle)) * (circleRadius - 20);
let y1 = centerY + sin(radians(angle + rotationAngle)) * (circleRadius - 20);
let x2 = centerX + cos(radians(angle + rotationAngle)) * 150;
let y2 = centerY + sin(radians(angle + rotationAngle)) * 150;
// Generate a random color for each line
let randomColor = color(random(100, 255), random(100, 255), random(100, 255), 150);
stroke(randomColor);
strokeWeight(2);
line(x1, y1, x2, y2);
}
// Add rotation to simulate the CD spinning
if (isClockwise) {
rotationAngle += rotationSpeed;
} else {
rotationAngle -= rotationSpeed;
}
}
function mousePressed() {
// Change the rotation direction when the mouse is clicked
isClockwise = !isClockwise;
}