UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

41 lines (36 loc) 1.28 kB
<html> <head> <title>Water</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/WaterModel.js' import ColorMap from 'https://agentscript.org/src/ColorMap.js' const model = new Model() model.setup() const patchColors = ColorMap.gradientColorMap(256, ['navy', 'aqua']) const maxZ = 10 const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 2, drawOptions: { // Patches only model: patchesColor: p => patchColors.scaleColor(p.zpos, -maxZ, maxZ), }, }) view.setPatchesSmoothing(true) // make water smoother const anim = new Animator( () => { model.step() view.draw() }, 500, // how many steps 30 // at fps steps/second ) </script> <div id="modelDiv"></div> </body> </html>