-
Notifications
You must be signed in to change notification settings - Fork 3
/
draw_vector.jl
68 lines (52 loc) · 1.6 KB
/
draw_vector.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
# 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 Luxor
function draw_sim(sim, p_size = 5, w_size = 600)
max_x = mapreduce(p -> p.x, max, sim.pop)
max_y = mapreduce(p -> p.y, max, sim.pop)
min_x = mapreduce(p -> p.x, min, sim.pop)
min_y = mapreduce(p -> p.y, min, sim.pop)
f_scale = 600 / max(max_x - min_x, max_y - min_y)
@svg begin
p_size = 5
origin(0, 0)
sethue("black")
for p in sim.pop
x1 = p.x * f_scale
y1 = p.y * f_scale
for p2 in p.contacts
x2 = p2.x * f_scale
y2 = p2.y * f_scale
setline(1)
setdash("solid")
line(Point(x1, y1), Point(x2, y2), :stroke)
end
end
for p in sim.pop
x = p.x * f_scale
y = p.y * f_scale
if p.status == infected
sethue("red")
elseif p.status == immune
sethue("green")
elseif p.status == susceptible
sethue("blue")
elseif p.status == dead
sethue("grey")
end
circle(Point(x, y), p_size, :fill)
end
end
end