UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

60 lines (52 loc) 1.79 kB
<html> <head> <title>exit</title> </head> <body> <script type="module"> import * as util from 'https://code.agentscript.org/src/utils.js' import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js' import Animator from 'https://code.agentscript.org/src/Animator.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 = { // turtlesShape: 'circle', turtlesColor: t => patchColors[t.exit.id], turtlesSize: 1, initPatches: (model, view) => patchColors, } const view = new TwoDraw( model, { div: 'modelDiv', patchSize: 8 }, drawOptions ) const anim = new Animator( () => { model.step() view.draw() }, 500, // run 500 steps 30 // 30 fps ) util.toWindow({ util, model, view, anim }) </script> <div id="modelDiv"></div> </body> </html>