UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

46 lines (41 loc) 1.54 kB
<html> <head> <title>Shapes</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/ShapesModel.js' import Shapes from 'https://agentscript.org/src/Shapes.js' const model = new Model() model.setup() const shapes = new Shapes() // add an image and emoji shapes await shapes.imagePathPromise('twitter', '/models/data/twitter.png') shapes.createEmojiPath('tree', 0x1f332) function turtleName(t) { // scan through the available shapes by turtle id return shapes.nameAtIndex(t.id) } const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 20, drawOptions: { turtlesShape: t => turtleName(t), turtlesSize: t => 3, turtlesRotate: t => !['lion', 'smiley', 'tree'].includes(turtleName(t)), }, }) const anim = new Animator( () => { model.step() view.draw() }, 500, // how many steps 30 // at fps steps/second ) </script> <div id="modelDiv"></div> </body> </html>