xxxxxxxxxx
35
class Spirograph {
constructor(R, r, d) {
this.R = int(random(25,350));
this.r = int(random(25,350));
this.d = int(random(5,150));
this.angle = random(0, TWO_PI);
this.x = 0;
this.y = 0;
this.calculate();
this.prevX = this.y;
this.prevY = this.x;
}
calculate() {
this.x = (this.r+this.r)*(tan(this.angle))-this.d*0.41*tan((this.R-this.r)/this.r*this.angle*2);
this.y = (this.R-this.r)*tan(sin(this.angle*1.8))+this.d*0.57*cos((this.R+this.r)/this.r*this.angle);
}
draw() {
this.calculate();
if (dist(this.x, this.y, this.prevX, this.prevY) > width/4) {
this.prevX = this.x;
this.prevY = this.y;
}
// stroke(0,50)
// line(this.x, this.y, this.prevX, this.prevY);
point(this.x, this.y);
this.prevX = this.x;
this.prevY = this.y;
this.angle += 0.02;
}
}