agentscript
Version:
AgentScript Model in Model/View architecture
51 lines (45 loc) • 1.73 kB
HTML
<html>
<head>
<title>KelpForest</title>
</head>
<body>
<script type="module">
import Animator from 'https://agentscript.org/src/Animator.js'
import TwoDraw from 'https://agentscript.org/src/TwoDraw.js'
import Model from 'https://agentscript.org/models/KelpForestModel.js'
const model = new Model()
model.setup()
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 20,
drawOptions: {
turtlesSize: t => {
if (t.breed.name === 'urchin') return 1
if (t.breed.name === 'kelp') return 2
return 1.5 // seaStar
},
turtlesColor: t => {
if (t.breed.name === 'urchin') return 'purple'
if (t.breed.name === 'kelp') return 'green'
return 'orange' // seaStar
},
turtlesShape: t => {
if (t.breed.name === 'urchin') return 'circle'
if (t.breed.name === 'kelp') return 'dart'
return 'pentagon' // seaStar
},
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
5 * 365, // how many steps, here 5 years,
30 // at 30 steps/second
)
Object.assign(window, { model, view, anim }) // debugging
</script>
<div id="modelDiv"></div>
</body>
</html>