UNPKG

1.97 kBHTMLView Raw
1<html>
2
3<head>
4 <title>exit3d</title>
5</head>
6
7<body>
8 <script type="module">
9 import * as util from 'https://code.agentscript.org/src/utils.js'
10 import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.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 World from 'https://code.agentscript.org/src/World.js'
14
15 import Turtle3D from 'https://code.agentscript.org/src/Turtle3D.js'
16 import Animator from 'https://code.agentscript.org/src/Animator.js'
17 import Model from 'https://code.agentscript.org/models/ExitModel.js'
18
19 const model = new Model()
20 await model.startup()
21 model.setup()
22
23 // DrawOptions here due to using model
24 const patchColors = model.patches.map(p => {
25 switch (p.breed.name) {
26 case 'exits':
27 return ColorMap.Basic16.atIndex(p.exitNumber + 4)
28 case 'inside':
29 return Color.typedColor('black')
30 case 'wall':
31 return Color.typedColor('gray')
32 default:
33 return ColorMap.LightGray.randomColor()
34 }
35 })
36 const drawOptions = {
37 turtlesMesh: 'Obj3DMesh',
38 turtlesShape: 'Cone',
39 turtlesColor: t => patchColors[t.exit.id],
40 turtlesSize: 1,
41 initPatches: (model, view) => patchColors,
42 }
43
44 const view = new ThreeDraw(
45 model,
46 { div: 'modelDiv' },
47 drawOptions
48 )
49
50 util.toWindow({ util, model, view })
51
52 await new Animator(
53 () => {
54 model.step()
55 view.draw()
56 },
57 500, // run 500 steps
58 30 // 30 fps
59 )
60
61 view.idle()
62 </script>
63 <div id="modelDiv"></div>
64</body>
65
66</html>
\No newline at end of file