-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathPlanet.js
60 lines (51 loc) · 1.11 KB
/
Planet.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Planet {
constructor(x, y, radius, speed, colour) {
this.x = x;
this.y = y;
this.radius = radius || 70;
this.speed = speed || 0.0001;
this.colour = colour || "green";
}
getColour() { //get and set methods for colour, radius and speed
return this.colour;
}
setColour(colour) {
this.colour = colour;
}
getRadius() {
return this.radius;
}
setRadius(radius) {
this.radius = radius;
}
getSpeed() {
return this.speed;
}
setSpeed(speed) {
this.speed = speed;
}
setCoords(millis, rOrbit, rOrbit2) {
this.x = (sin(millis * this.speed) * rOrbit) / 2;
this.y = (cos(millis * this.speed) * rOrbit2) / 2;
}
display(g) {
if (g) {
g.fill(this.colour);
g.strokeWeight(5);
g.stroke(0); /**/
g.ellipse(this.x, this.y, this.radius, this.radius);
} else {
fill(this.colour);
strokeWeight(5);
stroke(0); /**/
ellipse(this.x, this.y, this.radius, this.radius);
}
}
overLapping() {
if (this.y < 0) {
return true;
} else {
return false;
}
}
}