-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHello3DModel.js
37 lines (31 loc) · 1.07 KB
/
Hello3DModel.js
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
import * as util from 'https://code.agentscript.org/src/utils.js'
import Model from 'https://code.agentscript.org/src/Model3D.js'
export default class Hello3DModel extends Model {
population = 100
speed = 0.1 // patches per step
wiggleAngle = 10 // degrees
linksToo = true // handy to show just turtles if false
// ======================
// We can use Model's constructor, due to using Model's default World.
// If you pass in world options, Model will use them
constructor() {
super() // use default world options.
}
setup() {
this.turtles.setDefault('atEdge', 'bounce')
this.turtles.create(this.population, t => {
t.setxyz(...this.world.random3DPoint())
})
if (this.linksToo)
this.turtles.ask(t => {
if (this.population > 1)
this.links.create(t, this.turtles.otherOneOf(t))
})
}
step() {
this.turtles.ask(t => {
t.left(util.randomCentered(this.wiggleAngle))
t.forward(this.speed)
})
}
}