-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathwallfollower.js
More file actions
39 lines (30 loc) · 1.04 KB
/
wallfollower.js
File metadata and controls
39 lines (30 loc) · 1.04 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
import TwoDraw from '/src/TwoDraw.js'
import Animator from '/src/Animator.js'
import Color from '/src/Color.js'
import Model from '/models/WallFollowerModel.js'
export default async function runModel(div, steps = 500, fps = 30) {
const model = new Model() // use model's default world options
await model.startup()
model.setup()
// ==============================
const wallsColor = Color.typedColor(222, 184, 135)
const backgroundColor = Color.typedColor('black')
const drawOptions = {
patchesColor: p =>
p.breed.name === 'walls' ? wallsColor : backgroundColor,
turtlesShape: 'dart',
turtlesSize: 2,
turtlesColor: t => (t.breed.name === 'lefty' ? 'green' : 'red'),
}
const view = new TwoDraw(model, { div }, drawOptions)
// ==============================
const anim = new Animator(
() => {
model.step()
view.draw()
},
steps, // how many steps
fps // at fps steps/second
)
return { model, view, anim }
}