UNPKG

1.79 kBHTMLView Raw
1<html>
2
3<head>
4 <title>Avalanche</title>
5</head>
6
7<body>
8 <script type="module">
9 import * as util from 'https://code.agentscript.org/src/utils.js'
10 import Animator from 'https://code.agentscript.org/src/Animator.js'
11 import Color from 'https://code.agentscript.org/src/Color.js'
12 import ColorMap from 'https://code.agentscript.org/src/ColorMap.js'
13 import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.js'
14 import AvalancheModel from 'https://code.agentscript.org/models/AvalancheModel.js'
15
16 const pi = Math.PI
17
18 /**
19 *
20 * View
21 *
22 * */
23 const colormap = ColorMap.gradientColorMap(20, ['rgb(98,52,18)', 'white'])
24 const drawOptions = {
25 patchesMesh: 'PointsMesh',
26 patchesSize: 4,
27 patchesColor: p => {
28 const pi2 = 2 * Math.PI
29 const aspect2 = (p.aspect + pi2) % pi2
30 const k = (Math.PI - Math.abs(aspect2 - Math.PI)) / Math.PI
31 const snow = colormap.scaleColor(p.snowDepth, 0, 6)
32 const foo = Color.typedColor(k * snow[0], k * snow[1], k * snow[2])
33 return foo
34 },
35 }
36
37 const model = new AvalancheModel()
38 await model.startup()
39 model.setup()
40
41 const view = new ThreeDraw(
42 model,
43 { div: 'modelDiv' },
44 drawOptions
45 )
46
47 util.toWindow({ util, model, view, ColorMap, Color })
48
49 await new Animator(
50 () => {
51 model.step()
52 view.draw()
53 },
54 500, // run 500 steps
55 30 // 30 fps
56 )
57
58 view.idle()
59 </script>
60 <div id="modelDiv"></div>
61</body>
62
63</html>
\No newline at end of file