xxxxxxxxxx
53
class Dot{
constructor(xcent, ycent, speed, radius){
this.xcent = xcent;
//x coordinate of the center of the circle the dot moves on
this.ycent = ycent;
//y coordinate of the center of the circle the dot moves on
this.speed = speed;
//changes the angular speed. The bigger the number, the smaller the speed change per dot, although this could be made more intuitive by inverting the speed value.
this.radius = radius; //radius of the dots
this.theta = 0;
this.x = this.xcent + this.radius * cos(this.theta);
//formula of the circle for x
this.y = this.ycent + this.radius * sin(this.theta);
//formula of the circle for y
}
getxcoord(){
return this.x;
} //value of the x coordinate of a dot
setxcent(x){
this.xcent = x;
} //change x coordinate of the center of the circle the dot moves on
getycoord(){
return this.y;
} //value of the x coordinate of a dot
setycent(y){
this.ycent = y;
} //change y coordinate of the center of the circle the dot moves on
show(){ //display the dots
stroke(128, 3, 252);
strokeWeight(10);
point(this.x, this.y);
noStroke();
}
move(){
this.theta = this.theta + PI / this.speed; //increment the value of the angle
this.x = this.xcent + this.radius * cos(this.theta); //formula of the circle for x
this.y = this.ycent + this.radius * sin(this.theta); //formula of the circle for y
}
drawline(){ //draws lines between dots
stroke(3, 252, 190);
strokeWeight(1); // If increased, dots disappear under the lines and a smoother, wave-like pattern emerges
line(this.x, this.y, this.xcent, this.ycent);
noStroke();
}
}