agentscript
Version:
AgentScript Model in Model/View architecture
65 lines (56 loc) • 1.9 kB
HTML
<html>
<head>
<title>Avalanche</title>
</head>
<body>
<script type="module">
import * as util from '/src/utils.js'
import Animator from '/src/Animator.js'
import Color from '/src/Color.js'
import ColorMap from '/src/ColorMap.js'
import ThreeDraw from '/src/ThreeDraw.js'
import AvalancheModel from '/models/AvalancheModel.js'
const pi = Math.PI
/**
*
* View
*
* */
const colormap = ColorMap.gradientColorMap(20, [
'rgb(98,52,18)',
'white',
])
const drawOptions = {
patchesMesh: 'PointsMesh',
patchesSize: 4,
patchesColor: p => {
const pi2 = 2 * Math.PI
const aspect2 = (p.aspect + pi2) % pi2
const k = (Math.PI - Math.abs(aspect2 - Math.PI)) / Math.PI
const snow = colormap.scaleColor(p.snowDepth, 0, 6)
const foo = Color.typedColor(
k * snow[0],
k * snow[1],
k * snow[2]
)
return foo
},
}
const model = new AvalancheModel()
await model.startup()
model.setup()
const view = new ThreeDraw(model, { div: 'modelDiv' }, drawOptions)
util.toWindow({ util, model, view, ColorMap, Color })
await new Animator(
() => {
model.step()
view.draw()
},
500, // run 500 steps
30 // 30 fps
)
view.idle()
</script>
<div id="modelDiv"></div>
</body>
</html>