agentscript
Version:
AgentScript Model in Model/View architecture
61 lines (52 loc) • 1.72 kB
HTML
<html>
<head>
<title>exit</title>
</head>
<body>
<script type="module">
import * as util from 'https://code.agentscript.org/src/utils.js'
import Animator from 'https://code.agentscript.org/src/Animator.js'
import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.js'
import Color from 'https://code.agentscript.org/src/Color.js'
import ColorMap from 'https://code.agentscript.org/src/ColorMap.js'
import Model from 'https://code.agentscript.org/models/ExitModel.js'
const model = new Model()
await model.startup()
model.setup()
// DrawOptions here due to using model
const patchColors = model.patches.map(p => {
switch (p.breed.name) {
case 'exits':
return ColorMap.Basic16.atIndex(p.exitNumber + 4)
case 'inside':
return Color.typedColor('black')
case 'wall':
return Color.typedColor('gray')
default:
return ColorMap.LightGray.randomColor()
}
})
const drawOptions = {
turtlesColor: t => patchColors[t.exit.id],
turtlesSize: 1,
initPatches: (model, view) => patchColors,
}
const view = new ThreeDraw(
model,
{ div: 'modelDiv' },
drawOptions
)
util.toWindow({ util, model, view })
await new Animator(
() => {
model.step()
view.draw()
},
500,
30
)
view.idle()
</script>
<div id="modelDiv"></div>
</body>
</html>