-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhello.html
62 lines (58 loc) · 1.97 KB
/
hello.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
<html>
<head>
<title>Hello</title>
</head>
<body>
<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'
class HelloModel extends Model {
constructor() {
super(World.defaultOptions()) // Default "NL" world
Object.assign(this, {
population: 100,
speed: 0.1,
wiggle: 0.1,
})
}
setup() {
this.turtles.setDefault('atEdge', 'bounce')
this.turtles.create(this.population, t => {
const patch = this.patches.oneOf()
t.setxy(patch.x, patch.y)
})
this.turtles.ask(t => {
this.links.create(t, this.turtles.otherOneOf(t))
})
}
step() {
this.turtles.ask(t => {
t.direction += util.randomCentered(this.wiggle)
t.forward(this.speed)
})
}
}
const model = new HelloModel()
model.setup()
const view = new TwoDraw(
model,
{ patchSize: 20 },
{
patchesColor: 'black',
linksColor: 'white',
turtlesColor: 'red',
}
)
util.timeoutLoop(
() => {
model.step()
view.draw()
},
500,
33
).then(() => console.log('done'))
</script>
</body>
</html>