-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathhelloButtons.html
More file actions
60 lines (51 loc) · 1.84 KB
/
helloButtons.html
File metadata and controls
60 lines (51 loc) · 1.84 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
<!DOCTYPE html>
<html>
<head>
<title>HelloButtons</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 Buttons from '/src/Buttons.js'
const model = new Model()
model.setup()
const view = new TwoDraw(model, {
div: 'modelDiv',
patchSize: 20,
drawOptions: {
turtlesColor: 'yellow',
turtlesSize: 3,
turtlesShape: 'bug',
linksColor: 'red',
linksWidth: 3,
// patchesMap: 'Jet', // for bright patch colors!
},
})
const anim = new Animator(
() => {
model.step()
view.draw()
},
-1, // run forever, use buttons to start/stop
30 // 30 fps
)
function setShape(shape) {
view.drawOptions.turtlesShape = shape
view.draw()
}
const buttons = new Buttons('buttonsDiv', [
{ name: 'on/off', cmd: () => anim.toggle() },
{ name: 'bug', cmd: () => setShape('bug') },
{ name: 'arrow', cmd: () => setShape('arrow') },
{ name: 'dart', cmd: () => setShape('dart') },
{ name: 'download image', cmd: () => view.downloadCanvas() },
])
</script>
<!-- Because the divs are block elements, the buttons will be right under the model. -->
<div id="modelDiv"></div>
<div id="buttonsDiv"></div>
</body>
</html>