agentscript
Version:
AgentScript Model in Model/View architecture
42 lines (37 loc) • 1.3 kB
HTML
<html>
<head>
<title>WallFollower</title>
</head>
<body>
<script type="module">
import Animator from 'https://agentscript.org/src/Animator.js'
import TwoDraw from 'https://agentscript.org/src/TwoDraw.js'
import Model from 'https://agentscript.org/models/WallFollowerModel.js'
const model = new Model()
model.setup()
const wallsColor = 'rgb(222, 184, 135)'
const backgroundColor = 'black'
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 10,
drawOptions: {
patchesColor: p =>
p.breed.name === 'walls' ? wallsColor : backgroundColor,
turtlesShape: 'dart',
turtlesSize: 2,
turtlesColor: t =>
t.breed.name === 'lefty' ? 'green' : 'red',
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
500, // how many steps
30 // at fps steps/second
)
</script>
<div id="modelDiv"></div>
</body>
</html>