agentscript
Version:
AgentScript Model in Model/View architecture
48 lines (41 loc) • 1.42 kB
HTML
<html>
<head>
<title>Shapes</title>
</head>
<body>
<script type="module">
import Animator from 'https://code.agentscript.org/src/Animator.js'
import TwoDraw from 'https://code.agentscript.org/src/TwoDraw.js'
import Model from 'https://code.agentscript.org/models/ShapesModel.js'
import Shapes from 'https://code.agentscript.org/src/Shapes.js'
const model = new Model()
model.setup()
const shapes = new Shapes()
// add an image and emoji shapes
await shapes.imagePathPromise(
'twitter',
'https://code.agentscript.org/models/data/twitter.png'
)
shapes.createEmojiPath('tree', 0x1f332)
// scan through the available shapes by turtle id
function turtleName(t) {
return shapes.nameAtIndex(t.id)
}
const drawOptions = {
turtlesShape: t => turtleName(t),
turtlesSize: t => 3,
turtlesRotate: t => !['lion', 'smiley', 'tree'].includes(turtleName(t)),
}
const view = new TwoDraw(model, { div: 'modelDiv', patchSize: 20, drawOptions })
const anim = new Animator(
() => {
model.step()
view.draw()
},
500, // how many steps
30 // at fps steps/second
)
</script>
<div id="modelDiv"></div>
</body>
</html>