-
Notifications
You must be signed in to change notification settings - Fork 0
/
planet.js
94 lines (76 loc) · 2.14 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function planet(c, d, r, s, n) {
var colour = c;
var distance = d;
var radius = r;
var name = n;
var angle = TWO_PI;
var speed = s;
var moons = [];
this.addMoon = function() {
var md = distance / random(8,6);
var mr = radius / random(9,3);
var ms = speed * random(1, 4);
var moon = new planet(250, md+4, mr, ms*2, '');
moons.push(moon);
};
this.addSmallMoon = function() {
var md = distance / random(6,4);
var mr = radius / random(9,3);
var ms = speed * random(6, 14);
var moon = new planet(250, md/2, mr, ms*2, '');
moons.push(moon);
};
this.addMediumMoon = function() {
var md = distance / random(8,6);
var mr = radius / random(9,3);
var ms = speed * random(1, 4);
var moon = new planet(250, md+4, mr, ms, '');
moons.push(moon);
};
this.update = function() {
angle += speed;
}
this.getName = () => name;
this.show = function() {
push();
fill(colour);
rotate(angle);
translate(distance, 0);
ellipse(0,0,radius,radius);
textLeading(20);
if (name === "Sun") {
fill(0)
textSize(24);
text(name, -20, 5);
} else if (name === "Jupiter") {
fill(255)
text(name, -25, -45);
} else if (name === "Saturn") {
fill(255)
text(name, -25, -35);
} else if (name === "Mars") {
fill(255)
text(name, -15, -20);
} else if (name === "Mercury") {
fill(255)
text(name, -25, -25);
} else if (name === "Earth") {
fill(255)
text(name, -20, -25);
} else if (name === "Venus") {
fill(255)
text(name, -25, -25);
} else if (name === "Uranus") {
fill(255)
text(name, -25, -25);
} else if (name === "Neptune") {
fill(255);
text(name, -25, -25);
}
for(var m = 0; m < moons.length; m++) {
moons[m].update();
moons[m].show();
};
pop();
};
};