-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathhelloGui.html
More file actions
75 lines (68 loc) · 2.16 KB
/
helloGui.html
File metadata and controls
75 lines (68 loc) · 2.16 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
<!DOCTYPE html>
<html>
<head>
<title>HelloGui</title>
</head>
<body>
<script type="module">
import * as util from '/src/utils.js'
import Model from '/models/HelloModel.js'
import Animator from '/src/Animator.js'
import TwoDraw from '/src/TwoDraw.js'
import GUI from '/src/GUI.js'
const model = new Model()
model.setup()
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 20,
drawOptions: {
turtlesSize: 3,
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
-1, // run forever, use GUI to start/stop
30 // 30 fps
)
// Each of the 7 gui types:
const gui = new GUI({
fps: {
slider: [30, [5, 60, 5]],
cmd: val => anim.setFps(val),
},
turtlesShape: {
chooser: ['bug', ['bug', 'dart', 'person']],
cmd: val => (view.drawOptions.turtlesShape = val),
},
turtlesColor: {
color: '#ff0000',
cmd: val => (view.drawOptions.turtlesColor = val),
},
pause: {
switch: false,
cmd: val => {
if (val) {
anim.stop()
} else {
anim.start()
}
},
},
setTitle: {
input: document.title,
cmd: val => (document.title = val),
},
downloadCanvas: {
button: () => view.downloadCanvas(),
},
modelTicks: {
monitor: [model, 'ticks'],
},
})
</script>
<div id="modelDiv"></div>
</body>
</html>