UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

45 lines (38 loc) 1.4 kB
<html> <head> <title>Avalanche</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/AvalancheModel.js' import Color from 'https://code.agentscript.org/src/Color.js' import ColorMap from 'https://code.agentscript.org/src/ColorMap.js' const model = new Model() await model.startup() model.setup() const pi = Math.PI const snowColor = ColorMap.gradientColorMap(20, ['rgb(98,52,18)', 'white']) const drawOptions = { patchesColor: p => { const aspect2 = (p.aspect + 2 * pi) % (2 * pi) const k = (pi - Math.abs(aspect2 - pi)) / pi const snow = snowColor.scaleColor(p.snowDepth, 0, 6) const col = Color.typedColor(k * snow[0], k * snow[1], k * snow[2]) return col }, } const view = new TwoDraw(model, { div: 'modelDiv', drawOptions }) const anim = new Animator( () => { model.step() view.draw() }, 500, // how many steps 30 // at fps steps/second ) </script> <div id="modelDiv"></div> </body> </html>