Published
Edited
Feb 10, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
class DiffuseModel extends Model {
setup () {
// this.patches.own('ran ds')
this.turtles.setDefault('speed', 0.5)
this.turtles.setDefault('atEdge', 'wrap')
this.turtles.setDefault('size', 5)
this.population = 2
this.radius = 6

this.patches.ask(p => {
p.ran = util.randomFloat(1.0)
// p.ds = 0
})

this.patches.nOf(this.population).ask(p => {
p.sprout(1, this.turtles)
})
}
step () {
this.turtles.ask((t) => {
t.theta += util.randomCentered(0.1)
t.forward(t.speed)
this.patches.inRadius(t.patch, this.radius, true).ask(p => {
p.ran = Math.min(p.ran + 0.1, 0.8)
})
})

this.patches.diffuse('ran', 0.05)
}
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more