agentscript
Version:
AgentScript Model in Model/View architecture
65 lines (58 loc) • 2.36 kB
HTML
<html>
<head>
<title>Roads</title>
</head>
<body>
<script type="module">
import * as util from 'https://agentscript.org/src/utils.js'
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/RoadsModel.js'
// import santafeRoads from 'https://agentscript.org/models/data/santaferoads.json' with { type: 'json' }
const model = new Model() // default world options includes santafeRoads
model.setup()
console.log('model bbox', model.world.bbox)
// const baseMapTile = await util.imagePromise(
// '/models/data/roads14.png'
// )
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 6,
drawOptions: {
// patchesColor: baseMapTile,
patchesColor: 'transparent',
turtlesColor: t =>
({
// nodes: 'red', intersections: 'blue', drivers: 'green'
// nodes: 'transparent', intersections: 'red', drivers: 'green'
nodes: 'rgba(0, 0, 0, 0.2)',
intersections: 'red',
drivers: 'green',
}[t.breed.name]),
turtlesSize: t =>
({
nodes: 1,
intersections: 2,
drivers: 5,
}[t.breed.name]),
turtlesShape: t =>
({
nodes: 'circle',
intersections: 'circle',
drivers: 'dart',
}[t.breed.name]),
linksColor: 'black',
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
-1, // run forever
10 // at fps steps/second
)
</script>
<div id="modelDiv"></div>
</body>
</html>