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
|
stars = [];
blackHoles = [];
animations = [];
levels = [];
Level = function(name, description, cameraCoords) {
this.name = name;
this.description = description;
this.cameraCoords = cameraCoords;
this.stars = [];
this.blackHoles = [];
this.animations = [];
levels.push(this);
}
Level.prototype.addStar = function(center, size, animation) {
var star = new Star(center, size);
this.stars.push(star);
if (animation) this.animations.push((t) => star.moveTo(animation(t, star)));
}
Level.prototype.addBlackHole = function(center, size, animation) {
var bh = new BlackHole(center, size);
this.blackHoles.push(bh);
if (animation) this.animations.push((t) => bh.moveTo(animation(t, bh)));
}
Level.prototype.load = function() {
stars = this.stars;
blackHoles = this.blackHoles;
animations = this.animations;
pos = this.cameraCoords;
}
function createLevels() {
var l1 = new Level(
"Star passing behind black hole",
"You can see how the black hole (correctly) warps the light of the star behind it when it passes",
[1000,0,650]);
l1.addStar([1100,0,1000], 10, (t, star) => [1100 -100 * (1 + Math.sin(t/300 + 1.5 * Math.PI)),0,1000]);
l1.addBlackHole([1000,0,900], 30, undefined);
}
|