UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

51 lines (45 loc) 1.66 kB
<html> <head> <title>Avalanche</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/AvalancheModel.js' import Color from 'https://agentscript.org/src/Color.js' import ColorMap from 'https://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>