-
Notifications
You must be signed in to change notification settings - Fork 2
/
planets.html
102 lines (92 loc) · 3.4 KB
/
planets.html
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
<html>
<head>
<title>ORB.js test model</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/gh/lizard-isana/[email protected]/build/orb.v2.js"></script>
<script type="module">
import World from 'https://agentscript.org/src/World.js'
import Model from 'https://agentscript.org/src/Model.js'
import util from 'https://agentscript.org/src/util.js'
import TwoDraw from 'https://agentscript.org/src/TwoDraw.js'
/**
Use ORB.js to display the planets
*/
class PlanetModel extends Model {
constructor() {
super(World.defaultOptions(36, 36)) // Default "NL" world
this.planets = [
'Sun',
'Mercury',
'Venus',
'Earth',
/*"Moon"*/
'Mars',
'Jupiter',
'Saturn',
'Uranus',
'Neptune',
]
this.date = new Date()
}
setup() {
this.turtles.setDefault('atEdge', 'bounce')
this.planets.forEach(name => {
this.turtles.create(1, t => {
const patch = this.patches.oneOf()
t.setxy(0, 0)
t.planetName = name
})
})
}
step() {
this.turtles.ask(t => {
try {
let xyz
if (t.planetName == 'Sun') {
t.x = t.y = 0
} else {
const planet = new Orb.VSOP(t.planetName)
xyz = planet.xyz(this.date) // ecliptic rectangular coordinates(x, y, z)
t.x = xyz.x
t.y = xyz.y
}
document.getElementById(
'dateDiv'
).innerHTML = `${this.date.toISOString()}`
this.date.setDate(this.date.getDate() + 1)
} catch (err) {
console.error(err)
}
})
}
}
const model = new PlanetModel()
model.setup()
util.toWindow({ model, util, World })
const view = new TwoDraw(
model,
{ div: 'modelDiv', patchSize: 14 },
{
patchesColor: 'black',
turtlesShape: 'circle',
turtlesColor: 'random',
turtlesSize: 1,
textProperty: 'planetName',
textColor: 'white',
textSize: 1,
}
)
util.timeoutLoop(
() => {
model.step()
view.draw()
},
9000,
33
).then(() => console.log('done'))
</script>
<div id="modelDiv"></div>
<div id="dateDiv"></div>
</body>
</html>