xxxxxxxxxx
25
class Oscillator {
constructor(velocity, amplitude) {
this.angle = createVector();
this.position = createVector();
this.velocity = velocity;
this.amplitude = amplitude;
}
oscillate() {
this.angle.add(this.velocity);
this.position.x = this.amplitude.x * sin(this.angle.x);
this.position.y = this.amplitude.y * sin(this.angle.y);
}
display() {
push();
translate(width / 2, height / 2);
stroke(0);
fill(175);
line(0, 0, this.position.x, this.position.y);
circle(this.position.x, this.position.y, 16);
pop();
}
}