- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathHelloModel.js
More file actions
Latest commit
45 lines (38 loc) · 1.45 KB
/
Copy pathHelloModel.js
File metadata and controls
45 lines (38 loc) · 1.45 KB
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
importModelfrom'/src/Model.js'
importWorldfrom'/src/World.js'
import*asutilfrom'/src/utils.js'
// Subclass class Model to create our new model, HelloModel
classHelloModelextendsModel{
population=10// number of turtles
speed=0.1// step size in patch units
wiggleAngle=10// wiggle angle in degrees
linksToo=true// handy to show just turtles if false
atEdge='bounce'// when turtle at edge: wrap bounce die clamp random
startAtCenter=true
// worldOptions: patches -16 to 16 or 33 x 33 with 0,0 origin
constructor(worldOptions=World.defaultOptions(16)){
super(worldOptions)
}
setup(){
// Have turtles "bounce" at the Patches edges. Default is to wrap
this.turtles.setDefault('atEdge',this.atEdge)
// create "population" turtles placed on random patches
this.turtles.create(this.population,t=>{
if(!this.startAtCenter)t.moveTo(this.patches.oneOf())
})
// If links.too is true, create a link from every turtle to another turtle
if(this.linksToo){
this.turtles.ask(t=>{
this.links.create(t,this.turtles.otherOneOf(t))
})
}
}
step(){
// change heading randomly, moving forward by "speed"
this.turtles.ask(t=>{
t.heading+=util.randomCentered(this.wiggleAngle)
t.forward(this.speed)
})
}
}
exportdefaultHelloModel