agentscript
Version:
AgentScript Model in Model/View architecture
57 lines (47 loc) • 1.66 kB
HTML
<html>
<head>
<title>camera3d</title>
</head>
<body>
<script type="module">
import * as util from 'https://code.agentscript.org/src/utils.js'
import Color from 'https://code.agentscript.org/src/Color.js'
import ThreeDraw from 'https://code.agentscript.org/src/ThreeDraw.js'
import Animator from 'https://code.agentscript.org/src/Animator.js'
import Model from 'https://code.agentscript.org/models/Camera3DModel.js'
const isPixel = t => t.breed.name === 'pixels'
const uvToColor = t => {
const { u, v } = t
const r = Math.sqrt(u ** 2 + v ** 2)
return Color.toTypedColor(`hsl(${(r * 240) % 240}, 100%, 50%)`)
}
const drawOptions = {
turtlesMesh: { meshClass: 'Obj3DMesh', useAxes: true },
turtlesShape: t => (isPixel(t) ? 'Cube' : 'Dart'),
turtlesColor: t =>
isPixel(t) ? uvToColor(t) : Color.toTypedColor('red'),
turtlesSize: t => (isPixel(t) ? 0.35 : 3),
linksColor: l => uvToColor(l.end0),
}
const model = new Model()
await model.startup()
model.setup()
model.setHeadingPitchRollDelta(1, 1, 1)
const view = new ThreeDraw(model, {
div: document.body,
drawOptions,
})
util.toWindow({ util, model, view })
await new Animator(
() => {
model.step()
view.draw()
},
500, // run 500 steps
30 // 30 fps
)
view.idle()
</script>
<div id="modelDiv"></div>
</body>
</html>