- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDiffuseModel.js
More file actions
Latest commit
53 lines (43 loc) · 1.39 KB
/
Copy pathDiffuseModel.js
File metadata and controls
53 lines (43 loc) · 1.39 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
46
47
48
49
50
51
52
53
importWorldfrom'/src/World.js'
importModelfrom'/src/Model.js'
import*asutilfrom'/src/utils.js'
exportdefaultclassDiffuseModelextendsModel{
population=4
speed=0.5
wiggleAngle=10
startAtCenter=false
radius=6
diffuseRate=0.05
seedDelta=0.1
seedMax=0.8
centerPatch
// ======================
constructor(worldOptions=World.defaultOptions(100)){
super(worldOptions)
}
setup(){
this.patches.ask(p=>{
p.ran=util.randomFloat(1.0)
})
// this.patches.nOf(this.population).ask(p => {
// p.sprout(1, this.turtles)
// })
this.turtles.create(this.population,t=>{
if(!this.startAtCenter)t.moveTo(this.patches.oneOf())
})
// this.centerPatch = this.patches.avg('ran') * 10
this.centerPatch=this.patches.patch(0,0).ran*10
}
step(){
this.turtles.ask(t=>{
t.heading+=util.randomCentered(this.wiggleAngle)
t.forward(this.speed)
this.patches.inRadius(t.patch,this.radius,true).ask(p=>{
p.ran=Math.min(p.ran+this.seedDelta,this.seedMax)
})
})
this.patches.diffuse('ran',this.diffuseRate)
// this.centerPatch = this.patches.avg('ran') * 10
this.centerPatch=this.patches.patch(0,0).ran*10
}
}