agentscript
Version:
AgentScript Model in Model/View architecture
41 lines (34 loc) • 1.21 kB
HTML
<html>
<head>
<title>WallFollower</title>
</head>
<body>
<script type="module">
import Animator from 'https://code.agentscript.org/src/Animator.js'
import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js'
import Model from 'https://code.agentscript.org/models/WallFollowerModel.js'
import Color from 'https://code.agentscript.org/src/Color.js'
const model = new Model()
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: 'modelDiv', patchSize: 10, drawOptions })
const anim = new Animator(
() => {
model.step()
view.draw()
},
500, // how many steps
30 // at fps steps/second
)
</script>
<div id="modelDiv"></div>
</body>
</html>