-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDiffuseModel.js
42 lines (35 loc) · 1.11 KB
/
DiffuseModel.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
38
39
40
41
42
import World from 'https://code.agentscript.org/src/World.js'
import Model from 'https://code.agentscript.org/src/Model.js'
import * as util from 'https://code.agentscript.org/src/utils.js'
export default class DiffuseModel extends Model {
population = 2
speed = 0.5
wiggleAngle = 10
radius = 6
diffuseRate = 0.05
seedDelta = 0.1
seedMax = 0.8
// ======================
constructor(worldOptions = World.defaultOptions(100)) {
super(worldOptions)
}
setup() {
this.turtles.setDefault('speed', this.speed)
this.patches.ask(p => {
p.ran = util.randomFloat(1.0)
})
this.patches.nOf(this.population).ask(p => {
p.sprout(1, this.turtles)
})
}
step() {
this.turtles.ask(t => {
t.heading += util.randomCentered(this.wiggleAngle)
t.forward(t.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)
}
}