agentscript
Version:
AgentScript Model in Model/View architecture
45 lines (40 loc) • 1.3 kB
HTML
<html>
<head>
<title>Virus</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/VirusModel.js'
const model = new Model()
model.setup()
const turtleColors = {
infected: 'red',
susceptible: 'blue',
resistant: 'gray',
}
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 10,
drawOptions: {
patchesColor: 'black',
turtlesShape: 'circle',
turtlesSize: 1.5,
turtlesColor: t => turtleColors[t.state],
linksColor: 'white',
linksWidth: 2,
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
500, // how many steps
30 // at fps steps/second
)
</script>
<div id="modelDiv"></div>
</body>
</html>