Skip to content

Commit 66cb882

Browse files
committed
Update planets.html
1 parent ec54590 commit 66cb882

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

planets.html

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,91 +6,95 @@
66
<script src="https://cdn.jsdelivr.net/gh/lizard-isana/[email protected]/build/orb.v2.js"></script>
77

88
<script type="module">
9-
import {
10-
World,
11-
Model,
12-
util,
13-
} from 'https://backspaces.github.io/agentscript/dist/agentscript.esm.js'
14-
// import TwoView from 'https://backspaces.github.io/agentscript/src/TwoView.js'
15-
import Shapes from 'https://backspaces.github.io/agentscript/src/Shapes.js'
16-
import ColorMap from 'https://backspaces.github.io/agentscript/src/ColorMap.js'
17-
import TwoDraw from 'https://backspaces.github.io/agentscript/src/TwoDraw.js'
9+
import World from 'https://agentscript.org/src/World.js'
10+
import Model from 'https://agentscript.org/src/Model.js'
11+
import util from 'https://agentscript.org/src/util.js'
12+
import TwoDraw from 'https://agentscript.org/src/TwoDraw.js'
13+
1814
/**
1915
Use ORB.js to display the planets
2016
2117
*/
2218
class PlanetModel extends Model {
2319
constructor() {
24-
super(World.defaultOptions(36,36)) // Default "NL" world
25-
this.planets = ["Sun","Mercury","Venus","Earth",/*"Moon"*/,"Mars","Jupiter","Saturn","Uranus","Neptune"]
26-
this.date = new Date();
20+
super(World.defaultOptions(36, 36)) // Default "NL" world
21+
this.planets = [
22+
'Sun',
23+
'Mercury',
24+
'Venus',
25+
'Earth' /*"Moon"*/,
26+
,
27+
'Mars',
28+
'Jupiter',
29+
'Saturn',
30+
'Uranus',
31+
'Neptune',
32+
]
33+
this.date = new Date()
2734
}
2835
setup() {
2936
this.turtles.setDefault('atEdge', 'bounce')
30-
this.planets.forEach(name=>{
37+
this.planets.forEach(name => {
3138
this.turtles.create(1, t => {
3239
const patch = this.patches.oneOf()
33-
t.setxy(0,0)
40+
t.setxy(0, 0)
3441
t.planetName = name
3542
})
3643
})
3744
}
3845
step() {
3946
this.turtles.ask(t => {
40-
try{
47+
try {
4148
let xyz
42-
if (t.planetName == 'Sun'){
43-
t.x=t.y=0
44-
} else{
45-
const planet = new Orb.VSOP(t.planetName);
46-
xyz = planet.xyz(this.date); // ecliptic rectangular coordinates(x, y, z)
47-
t.x=xyz.x
48-
t.y=xyz.y
49+
if (t.planetName == 'Sun') {
50+
t.x = t.y = 0
51+
} else {
52+
const planet = new Orb.VSOP(t.planetName)
53+
xyz = planet.xyz(this.date) // ecliptic rectangular coordinates(x, y, z)
54+
t.x = xyz.x
55+
t.y = xyz.y
4956
}
50-
51-
document.getElementById('dateDiv').innerHTML = `${this.date.toISOString()}`
57+
58+
document.getElementById(
59+
'dateDiv'
60+
).innerHTML = `${this.date.toISOString()}`
5261
this.date.setDate(this.date.getDate() + 1)
53-
} catch(err) {
62+
} catch (err) {
5463
console.error(err)
5564
}
5665
})
5766
}
5867
}
5968

60-
const shapes = new Shapes()
61-
const colorMap = ColorMap.Bright16
6269
const model = new PlanetModel()
6370
model.setup()
6471

6572
util.toWindow({ model, util, World })
6673

67-
// Use the model's world for the view:
68-
const view = new TwoDraw(model, { div:'modelDiv',patchSize: 8 })
69-
function draw() {
70-
view.clear('black')
71-
view.draw({
72-
turtleShape: 'circle',
73-
turtleColor: 'random',
74-
turtleSize: 1,
75-
patchColor: 'black',
74+
const view = new TwoDraw(
75+
model,
76+
{ div: 'modelDiv', patchSize: 14 },
77+
{
78+
patchesColor: 'black',
79+
turtlesShape: 'circle',
80+
turtlesColor: 'random',
81+
turtlesSize: 1,
7682
textProperty: 'planetName',
7783
textColor: 'white',
7884
textSize: 1,
79-
80-
})
81-
}
85+
}
86+
)
8287

8388
util.timeoutLoop(
8489
() => {
8590
model.step()
86-
draw()
91+
view.draw()
8792
},
8893
9000,
8994
33
9095
).then(() => console.log('done'))
91-
9296
</script>
93-
<div id='modelDiv'></div>
94-
<div id='dateDiv'></div>
97+
<div id="modelDiv"></div>
98+
<div id="dateDiv"></div>
9599
</body>
96100
</html>

0 commit comments

Comments
 (0)