UNPKG

1.66 kBHTMLView Raw
1<html>
2
3<head>
4 <title>camera3d</title>
5</head>
6
7<body>
8 <script type="module">
9 import * as util from 'https://code.agentscript.org/src/utils.js'
10 import Color from 'https://code.agentscript.org/src/Color.js'
11 import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.js'
12 import Animator from 'https://code.agentscript.org/src/Animator.js'
13 import Model from 'https://code.agentscript.org/models/Camera3DModel.js'
14
15 const isPixel = t => t.breed.name === 'pixels'
16 const uvToColor = t => {
17 const { u, v } = t
18 const r = Math.sqrt(u ** 2 + v ** 2)
19 return Color.toTypedColor(`hsl(${(r * 240) % 240}, 100%, 50%)`)
20 }
21 const drawOptions = {
22 turtlesMesh: { meshClass: 'Obj3DMesh', useAxes: true },
23 turtlesShape: t => (isPixel(t) ? 'Cube' : 'Dart'),
24 turtlesColor: t =>
25 isPixel(t) ? uvToColor(t) : Color.toTypedColor('red'),
26 turtlesSize: t => (isPixel(t) ? 0.35 : 3),
27 linksColor: l => uvToColor(l.end0),
28 }
29
30 const model = new Model()
31 await model.startup()
32 model.setup()
33
34 model.setHeadingPitchRollDelta(1, 1, 1)
35
36 const view = new ThreeDraw(model, {
37 div: document.body,
38 drawOptions,
39 })
40
41 util.toWindow({ util, model, view })
42
43 await new Animator(
44 () => {
45 model.step()
46 view.draw()
47 },
48 500, // run 500 steps
49 30 // 30 fps
50 )
51
52 view.idle()
53 </script>
54 <div id="modelDiv"></div>
55</body>
56
57</html>
\No newline at end of file