-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.html
More file actions
98 lines (82 loc) · 3.11 KB
/
index.html
File metadata and controls
98 lines (82 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<html>
<head>
<title>IDE</title>
<link rel="stylesheet" href="style.css" />
<!-- <link rel="preconnect" href="https://fonts.gstatic.com" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&family=Ubuntu+Mono&display=swap"
/> -->
</head>
<body>
<header id="navDiv">
<div class="button-row">
<a class="nav-button" href="./index.html">Agentscript</a>
<div class="spacer"></div>
<a class="nav-button" href="/editor/examples.html">Examples</a>
<a class="nav-button" href="/docs">Docs</a>
<a
class="nav-button"
href="https://github.com/backspaces/agentscript?tab=readme-ov-file#AgentScript"
>Code</a
>
</div>
</header>
<div id="modelDiv"></div>
<div id="textDiv">
<div class="title">Agentscript</div>
<div class="subtitle">agent based modeling in the browser</div>
<a class="learnmore" href="./Snippets.html">learn more</a>
</div>
<script type="module">
import Animator from '/src/Animator.js'
import TwoDraw from '/src/TwoDraw.js'
import AntsOptions from './Ants.js'
import DartsOptions from './Darts.js'
console.log('Ants', AntsOptions)
console.log('Darts', DartsOptions)
let ModelOptions = DartsOptions
// let { Model, patchSize, drawOptions } = ModelOptions
let anim
async function updateSize() {
if (anim) anim.stop()
const { Model, patchSize, drawOptions } = ModelOptions
const options = TwoDraw.fullScreenOptions(patchSize, 'white', 0)
const model = new Model(options)
model.setup()
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize,
drawOptions,
})
anim = new Animator(
() => {
model.step()
view.draw()
if (model.ticks === 250) switchModel()
},
-1, // run forever
30 // at 30 steps/second
)
}
function switchModel() {
anim.reset()
ModelOptions =
ModelOptions === AntsOptions ? DartsOptions : AntsOptions
updateSize()
}
updateSize()
window.addEventListener('resize', updateSize)
document
.getElementById('modelDiv')
.addEventListener('contextmenu', e => {
e.preventDefault()
})
document
.getElementById('textDiv')
.addEventListener('contextmenu', e => {
e.preventDefault()
})
</script>
</body>
</html>