xxxxxxxxxx
26
class Spiral {
// Constructor function to initialize a new spiral object with specified parameters
constructor(x, y, radius, color, speed) {
// Initialize object properties based on input parameters
this.x = x; // X-coordinate of the center of the spiral
this.y = y; // Y-coordinate of the center of the spiral
this.radius = radius; // Radius of the spiral
this.color = color; // Color of the spiral (as an array [R, G, B])
this.angle = 0; // Initial angle of the spiral
this.speed = speed; // Speed of rotation for the spiral
}
// Display function to draw the spiral on the canvas
display() {
noStroke(); // Disable stroke (outline)
fill(this.color); // Set fill color based on the color property
let spiralSize = this.radius * this.angle; // Calculate the size of the spiral
// Draw a small ellipse at a point on the spiral determined by the current angle
ellipse(this.x + cos(this.angle) * spiralSize, this.y + sin(this.angle) * spiralSize, 5, 5);
}
// Move function to update the angle of the spiral, causing it to rotate
move() {
this.angle += this.speed; // Increment the angle by the rotation speed
}
}