UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

58 lines (47 loc) 1.58 kB
<!DOCTYPE html> <html> <head> <title>HelloButtons</title> </head> <body> <div id="modelDiv"></div> <div id="buttonsDiv"></div> <script type="module"> import * as util from 'https://code.agentscript.org/src/utils.js' import Model from 'https://code.agentscript.org/models/HelloModel.js' import Animator from 'https://code.agentscript.org/src/Animator.js' import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js' import Buttons from 'https://code.agentscript.org/src/Buttons.js' const model = new Model() await model.startup() model.setup() const drawOptions = { turtlesSize: 3, } const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 20, drawOptions }) const anim = new Animator( () => { model.step() view.draw() }, -1, // run forever, use buttons to start/stop 30 // 30 fps ) function setShape(shape) { view.drawOptions.turtlesShape = shape; view.draw(); } const buttons = new Buttons('buttonsDiv', [ { name: "on/off", cmd: () => anim.toggle() }, { name: "circle", cmd: () => setShape("circle") }, { name: "arrow", cmd: () => setShape("arrow") }, { name: "dart", cmd: () => setShape("dart") }, { name: "make image", cmd: () => view.downloadCanvas() }, ]) </script> </body> </html>