xxxxxxxxxx
34
class Dots {
constructor(x, y) {
this.x = x; // x position of the dot
this.y = y; // y position of the dot
this.diameter = random(3, 7); // Diameter of the dot
this.color = color(random(255), random(255), random(255)); // color for the dot - random
}
// Function to move the dot
move() {
// Create two different movement patterns based on `flowDirection`
if (flowDirection === 0) {
this.x += random(-2, 2); // Random jitter in the x direction
this.y += random(-2, 2); // Random jitter in the y direction
} else {
this.x += sin(this.y * 0.05) * 2; // Wavy movement based on the y-coordinate
this.y += cos(this.x * 0.05) * 2; // Wavy movement based on the x-coordinate
}
// Wrap around the edges of the canvas
if (this.x > width) this.x = 0;
if (this.x < 0) this.x = width;
if (this.y > height) this.y = 0;
if (this.y < 0) this.y = height;
}
// Function to display the dot on the canvas
display() {
noStroke();
fill(this.color); // random color
ellipse(this.x, this.y, this.diameter, this.diameter); // Draw the dot as a small circle
}
}