UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

37 lines (31 loc) 1.01 kB
<html> <head> <title>Buttons</title> </head> <body> <script type="module"> import Animator from 'https://code.agentscript.org/src/Animator.js' import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js' import Model from 'https://code.agentscript.org/models/ButtonsModel.js' const model = new Model() model.setup() const drawOptions = { turtlesColor: t => (model.cluster.has(t) ? 'red' : 'random'), turtlesShape: 'circle', turtlesSize: 2, linksColor: 'rgba(255, 255, 255, 0.50', } const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 20, drawOptions }) const anim = new Animator( () => { model.step() view.draw() if (model.done) anim.stop() }, -1, // run until model.done 30 // at fps steps/second ) </script> <div id="modelDiv"></div> </body> </html>