-
Notifications
You must be signed in to change notification settings - Fork 3
/
draw_gui.jl
72 lines (57 loc) · 1.72 KB
/
draw_gui.jl
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
# Copyright (C) 2020 Martin Hinsch <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
using SSDL
using SimpleGraph
using SimpleGui
### draw GUI
# draw world to canvas
function draw_world(canvas, model)
xs = canvas.xsize - 1
ys = canvas.ysize - 1
# draw connections
for p in model.pop
x1 = trunc(Int, p.x * xs) + 1
y1 = trunc(Int, p.y * ys) + 1
for p2 in p.contacts
x2 = trunc(Int, p2.x * xs) + 1
y2 = trunc(Int, p2.y * ys) + 1
line(canvas, x1, y1, x2, y2, red(255))
end
end
# draw agents
for p in model.pop
x = trunc(Int, p.x * xs) + 1
y = trunc(Int, p.y * ys) + 1
if p.status == infected
col = red(255)
elseif p.status == immune
col = green(255)
elseif p.status == susceptible
col = blue(255)
elseif p.status == dead
col = rgb(120, 120, 120)
end
circle_fill(canvas, x, y, 3, UInt32(col), true)
end
end
# draw both panels to video memory
function draw(model, graphs, gui)
clear!(gui.canvas)
draw_world(gui.canvas, model)
update!(gui.panels[1,1], gui.canvas)
clear!(gui.canvas)
draw_graph(gui.canvas, graphs)
update!(gui.panels[2, 1], gui.canvas)
end