|
6 | 6 | <script src=" https://cdn.jsdelivr.net/gh/lizard-isana/[email protected]/build/orb.v2.js" ></script>
|
7 | 7 |
|
8 | 8 | <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 | + |
18 | 14 | /**
|
19 | 15 | Use ORB.js to display the planets
|
20 | 16 |
|
21 | 17 | */
|
22 | 18 | class PlanetModel extends Model {
|
23 | 19 | 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() |
27 | 34 | }
|
28 | 35 | setup() {
|
29 | 36 | this.turtles.setDefault('atEdge', 'bounce')
|
30 |
| - this.planets.forEach(name=>{ |
| 37 | + this.planets.forEach(name => { |
31 | 38 | this.turtles.create(1, t => {
|
32 | 39 | const patch = this.patches.oneOf()
|
33 |
| - t.setxy(0,0) |
| 40 | + t.setxy(0, 0) |
34 | 41 | t.planetName = name
|
35 | 42 | })
|
36 | 43 | })
|
37 | 44 | }
|
38 | 45 | step() {
|
39 | 46 | this.turtles.ask(t => {
|
40 |
| - try{ |
| 47 | + try { |
41 | 48 | 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 |
49 | 56 | }
|
50 |
| - |
51 |
| - document.getElementById('dateDiv').innerHTML = `${this.date.toISOString()}` |
| 57 | + |
| 58 | + document.getElementById( |
| 59 | + 'dateDiv' |
| 60 | + ).innerHTML = `${this.date.toISOString()}` |
52 | 61 | this.date.setDate(this.date.getDate() + 1)
|
53 |
| - } catch(err) { |
| 62 | + } catch (err) { |
54 | 63 | console.error(err)
|
55 | 64 | }
|
56 | 65 | })
|
57 | 66 | }
|
58 | 67 | }
|
59 | 68 |
|
60 |
| - const shapes = new Shapes() |
61 |
| - const colorMap = ColorMap.Bright16 |
62 | 69 | const model = new PlanetModel()
|
63 | 70 | model.setup()
|
64 | 71 |
|
65 | 72 | util.toWindow({ model, util, World })
|
66 | 73 |
|
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, |
76 | 82 | textProperty: 'planetName',
|
77 | 83 | textColor: 'white',
|
78 | 84 | textSize: 1,
|
79 |
| - |
80 |
| - }) |
81 |
| - } |
| 85 | + } |
| 86 | + ) |
82 | 87 |
|
83 | 88 | util.timeoutLoop(
|
84 | 89 | () => {
|
85 | 90 | model.step()
|
86 |
| - draw() |
| 91 | + view.draw() |
87 | 92 | },
|
88 | 93 | 9000,
|
89 | 94 | 33
|
90 | 95 | ).then(() => console.log('done'))
|
91 |
| - |
92 | 96 | </script>
|
93 |
| - <div id='modelDiv'></div> |
94 |
| - <div id='dateDiv'></div> |
| 97 | + <div id="modelDiv"></div> |
| 98 | + <div id="dateDiv"></div> |
95 | 99 | </body>
|
96 | 100 | </html>
|
0 commit comments