UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

61 lines (52 loc) 1.86 kB
<html> <head> <title>exit3d</title> </head> <body> <script type="module"> import * as util from '/src/utils.js' import ThreeDraw from '/src/ThreeDraw.js' // import Color from '/src/Color.js' import ColorMap from '/src/ColorMap.js' import World from '/src/World.js' import Turtle3D from '/src/Turtle3D.js' import Animator from '/src/Animator.js' import Model from '/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 'black' case 'wall': return 'gray' default: return ColorMap.LightGray.randomColor() } }) const drawOptions = { turtlesMesh: 'Obj3DMesh', turtlesShape: 'Cone', turtlesColor: t => patchColors[t.exit.id], turtlesSize: 1, initPatches: () => patchColors, } const view = new ThreeDraw(model, { div: 'modelDiv' }, drawOptions) util.toWindow({ util, model, view }) await new Animator( () => { model.step() view.draw() }, 500, // run 500 steps 30 // 30 fps ) view.idle() </script> <div id="modelDiv"></div> </body> </html>