-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
207 lines (174 loc) · 5.53 KB
/
sketch.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* SELECT or ENTER your screen size (minus the browser-bar at the top): */
// MacBook Air Display:
// let x_pixels = 1420;
// let y_pixels = 790;
// 1080p:
let x_pixels = 1900;
let y_pixels = 980;
/* UNCOMMENT below to include space-sound: */
// let song;
//
// function preload() {
// soundFormats('mp3', 'ogg');
// song = loadSound('assets/earth.mp3');
// }
// Initialization of all objects of our solar system:
function setup() {
createCanvas(x_pixels, y_pixels);
stars = makeStars(70);
sun = new Sun(width/2, height/2, 60);
// INNER PLANETS: ########################################################
mercury = new Planet(sun.x, sun.y, 3, 182, 184, 184, 80, 0.015);
venus = new Planet(sun.x, sun.y, 4, 255, 220, 100, 95, 0.013);
// EARTH and moon:
earth = new Planet(sun.x, sun.y, 5, 28, 115, 255, 120, 0.011);
moon = new Moon(earth.x, earth.y, 2, 255, 255, 255, 10, 0.015);
// MARS and moons:
mars = new Planet(sun.x, sun.y, 4, 212, 90, 19, 150, 0.009);
phobos = new Moon(mars.x, mars.y, 1.5, 250, 200, 200, 12, 0.011);
daimos = new Moon(mars.x, mars.y, .5, 255, 255, 255, 8, 0.015);
// BELT:
asteroids = makeBelt(100, 190);
// OUTER PLANETS: ########################################################
// JUPITER and moons:
jupiter = new Planet(sun.x, sun.y, 20, 181, 139, 34, 250, 0.006);
callisto = new Moon(jupiter.x, jupiter.y, 3, 250, 200, 200, 30, 0.01);
ganymede = new Moon(jupiter.x, jupiter.y, 4, 250, 200, 200, 35, 0.012);
europa = new Moon(jupiter.x, jupiter.y, 2, 250, 200, 200, 40, 0.01);
io = new Moon(jupiter.x, jupiter.y, 1, 250, 200, 0, 45, 0.009);
// SATURN and moons:
saturn = new DiskPlanet(sun.x, sun.y, 14, 255, 198, 54, 320, 0.005);
enceladus = new Moon(saturn.x, saturn.y, 4, 255, 255, 255, 19, 0.01);
titan = new Moon(saturn.x, saturn.y, 3, 255, 255, 0, 20, 0.009);
mimas = new Moon(saturn.x, saturn.y, 2, 200, 200, 200, 23, 0.007);
// URANUS and moons:
uranus = new Planet(sun.x, sun.y, 12, 187, 237, 237, 380, 0.004);
umbriel = new Moon(uranus.x, uranus.y, 3, 200, 200, 200, 20, 0.012);
titania = new Moon(uranus.x, uranus.y, 2, 200, 200, 200, 25, 0.01);
oberon = new Moon(uranus.x, uranus.y, 1.5, 200, 200, 200, 30, 0.008);
ariel = new Moon(uranus.x, uranus.y, 1, 200, 200, 200, 34, 0.007);
// NEPTUNE and moon:
neptune = new Planet(sun.x, sun.y, 10, 0, 10, 255, 450, 0.003);
triton = new Moon(neptune.x, neptune.y, 1.5, 255, 255, 255, 22, 0.01);
pluto = new Planet(sun.x, sun.y, 2, 255, 200, 10, 480, 0.002);
charon = new Moon(pluto.x, pluto.y, 0.5, 255, 255, 255, 5, 0.015);
// Oort Cloud:
oort = makeBelt(200, 540);
}
// Draw stars in the background:
function makeStars(amount) {
var stars = [];
for (i = 0; i < amount; i++) {
var rand_x = floor(random(x_pixels)) + 1;
var rand_y = floor(random(y_pixels)) + 1;
var size = floor(random(3)) + 1;
var star = new Star(rand_x, rand_y, size, 200, 255, 200);
console.log("Created new star! " + (i + 1).toString());
stars.push(star);
}
return stars;
}
// Draw stars in the background:
function makeBelt(amount, distance) {
var belt = [];
for (i = 0; i < amount; i++) {
var rand_x = floor(random(x_pixels)) + 1;
var rand_y = floor(random(y_pixels)) + 1;
var size = floor(random(2)) + 1;
var distance_range = floor(random() * ((distance + 10) - (distance - 10)) + distance - 10);
var asteroid = new Planet(sun.x, sun.y, size, 92, 64, 51, distance_range, 0.0005);
console.log("Created new star! " + (i + 1).toString());
belt.push(asteroid);
}
return belt;
}
// Draws multiple objects at once:
function drawStars(objects) {
for (i = 0; i < objects.length; i++) {
// console.log(objects[i].x)
objects[i].show();
}
}
// Draws multiple objects at once:
function drawBelt(objects) {
for (i = 0; i < objects.length; i++) {
// console.log(objects[i].x)
objects[i].show();
objects[i].checkPosition(sun);
}
}
// Handles all planets:
function handlePlanets() {
mercury.show();
venus.show();
earth.show();
mars.show();
jupiter.show();
saturn.show();
uranus.show();
neptune.show();
pluto.show();
mercury.checkPosition(sun);
venus.checkPosition(sun);
earth.checkPosition(sun);
mars.checkPosition(sun);
jupiter.checkPosition(sun);
saturn.checkPosition(sun);
uranus.checkPosition(sun);
neptune.checkPosition(sun);
pluto.checkPosition(sun);
}
// Handles all moons:
function handleMoons() {
// EARTH MOONS:
moon.show();
moon.checkPosition(earth);
// MARS MOONS:
phobos.show();
phobos.checkPosition(mars);
daimos.show();
daimos.checkPosition(mars);
// JUPITER MOONS:
callisto.show();
callisto.checkPosition(jupiter);
europa.show();
europa.checkPosition(jupiter);
ganymede.show();
ganymede.checkPosition(jupiter);
io.show();
io.checkPosition(jupiter);
// SATURN MOONS:
enceladus.show();
enceladus.checkPosition(saturn);
titan.show();
titan.checkPosition(saturn);
mimas.show();
mimas.checkPosition(saturn);
// URANUS MOONS:
umbriel.show();
umbriel.checkPosition(uranus);
titania.show();
titania.checkPosition(uranus);
oberon.show();
oberon.checkPosition(uranus);
ariel.show();
ariel.checkPosition(uranus);
//NEPTUNE MOON:
triton.show();
triton.checkPosition(neptune);
// PLUTO MOON:
charon.show();
charon.checkPosition(pluto);
}
// The MAIN draw function:
function draw() {
background(51);
drawStars(stars);
sun.show();
handlePlanets();
drawBelt(asteroids);
drawBelt(oort);
handleMoons();
/* UNCOMMENT below to play sounds: */
// song.play();
}