UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

41 lines (35 loc) 1.14 kB
<html> <head> <title>Tsp</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/TspModel.js' const model = new Model() model.setup() const drawOptions = { patchesColor: 'black', turtlesShape: 'circle', // turtlesSize of 0 will skip drawing this turle // here "travelers" are skipped turtlesSize: t => (t.breed.name === 'nodes' ? 2 : 0), turtlesColor: 'yellow', linksColor: 'red', linksWidth: 2, } const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 6, drawOptions }) const anim = new Animator( () => { model.step() view.draw() if (model.done) anim.stop() }, 500, // how many steps 30 // at fps steps/second ) </script> <div id="modelDiv"></div> </body> </html>