UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

66 lines (56 loc) 1.66 kB
<html> <head> <title>shapes</title> <link rel="icon" type="image/x-icon" href="../favicon.ico" /> </head> <body> <script type="module"> import * as util from '../src/utils.js' import TwoDraw from '../src/TwoDraw.js' import Animator from '../src/Animator.js' import Model from '../models/HelloModel.js' import World from '../src/World.js' import Shapes from '../src/Shapes.js' const shapes = new Shapes() async function addImages() { await shapes.imagePathPromise( 'twitter', '../models/data/twitter.png' ) await shapes.imagePathPromise( 'redfish', '../models/data/redfish.png' ) } function turtleName(t) { return shapes.nameAtIndex(t.id) } await addImages() const model = new Model(World.defaultOptions(25, 16)) model.population = 100 await model.startup() model.setup() const view = new TwoDraw( model, { div: 'modelDiv', patchSize: 20, }, { turtlesShape: t => turtleName(t), turtlesSize: t => (turtleName(t) === 'redfish' ? 5 : 3), } ) 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>