-
Notifications
You must be signed in to change notification settings - Fork 0
/
Epicycle.js
45 lines (37 loc) · 1.06 KB
/
Epicycle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* A circle with a planet that has a position and a constant velocity
*/
class Epicycle {
constructor(position, initialDirectionVector, radialVelocity) {
this.position = position;
this.radialVelocity = radialVelocity;
this.size = initialDirectionVector.abs();
this.angle = atan2(initialDirectionVector.y, initialDirectionVector.x);
}
getPlanetPosition() {
return new Complex(
this.position.x + this.size * cos(this.angle),
this.position.y + this.size * sin(this.angle)
);
}
update() {
this.angle += this.radialVelocity * VELO;
}
draw(position) {
this.position = position;
// Draw vector
stroke(200);
strokeWeight(1);
line(this.position.x * SCALE,
this.position.y * SCALE,
(this.position.x + this.size * cos(this.angle)) * SCALE,
(this.position.y + this.size * sin(this.angle)) * SCALE
);
// Draw circle
stroke(80);
noFill();
const ax = this.position.x * SCALE;
const ay = this.position.y * SCALE;
circle(ax, ay, this.size * 2 * SCALE);
}
}