-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
144 lines (120 loc) · 3.38 KB
/
view.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const CANVAS_WIDTH = 950;
const CANVAS_HEIGHT = 650;
const MOBILE_CANVAS_WIDTH = 320;
const MOBILE_CANVAS_HEIGHT = 320;
const colors = { HEALTHY: "rgb(0, 123, 255)", INFECTED: "rgb(220, 53, 69)", DECEASED: "rgb(123, 123, 123)" }
const BOXES = [
{ x1: 30, y1: 30, x2: 300, y2: 300 },
{ x1: 330, y1: 30, x2: 600, y2: 300 },
{ x1: 630, y1: 30, x2: 900, y2: 300 },
// { x1: 30, y1: 330, x2: 300, y2: 600 },
{ x1: 330, y1: 330, x2: 600, y2: 600 },
{ x1: 630, y1: 330, x2: 900, y2: 600 }
]
const HOSPITAL = { x1: 30 + 20, y1: 330 + 20, x2: 300 - 20, y2: 600 - 20 };
const PERSON_RADIUS = 7;
function setup() {
let canvas;
if (onMobile()) {
canvas = createCanvas(MOBILE_CANVAS_WIDTH, MOBILE_CANVAS_HEIGHT);
BOXES.splice(4, 1);
BOXES.splice(2, 1);
}
else {
canvas = createCanvas(CANVAS_WIDTH, CANVAS_HEIGHT);
}
canvas.parent("canvas-container");
setGraphOptions();
setupControls();
setupPopulation();
}
function draw() {
if (onMobile()) {
scale(0.5);
}
background(0);
frameRate(FPS);
fill(0);
strokeWeight(3);
stroke(255);
BOXES.forEach(box => {
rect(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
// central location
rect(
(box.x1 + box.x2) / 2 - 10,
(box.y1 + box.y2) / 2 - 10,
((box.x1 + box.x2) / 2 + 10) - ((box.x1 + box.x2) / 2 - 10),
((box.y1 + box.y2) / 2 + 10) - ((box.y1 + box.y2) / 2 - 10)
);
});
rect(HOSPITAL.x1, HOSPITAL.y1, HOSPITAL.x2 - HOSPITAL.x1, HOSPITAL.y2 - HOSPITAL.y1);
nextRound();
drawPopulation();
}
function drawPopulation() {
stroke(0);
strokeWeight(1);
for (let i = 0; i < population.length; i++) {
const person = population[i];
if (person.status == status.INFECTED) {
noFill();
stroke(color("rgb(220, 53, 69)"));
ellipse(person.x, person.y, INFECTION_RADIUS, INFECTION_RADIUS);
stroke(0);
}
fill(color(colors[person.status]))
ellipse(person.x, person.y, PERSON_RADIUS, PERSON_RADIUS);
}
}
function setGraphOptions() {
Highcharts.setOptions({
chart: {
backgroundColor: "#000"
},
title: {
style: { color: '#bbb' }
},
credits: { enabled: false },
yAxis: { gridLineColor: '#333' },
legend: {
itemStyle: { color: '#bbb' },
itemHoverStyle: { color: '#FFF' },
itemHiddenStyle: { color: '#606063' }
}
});
}
function drawGraph() {
const graph = {};
graph.title = { text: "Epidemic Statistics" };
graph.xAxis = { categories: daysData };
graph.yAxis = {
title: { text: "Number of cases" }
};
graph.series = [
{
name: "Healthy",
data: healthyData,
color: colors[status.HEALTHY]
},
{
name: "Infected",
data: infectedData,
color: colors[status.INFECTED]
},
{
name: "Deceased",
data: deceasedData,
color: colors[status.DECEASED]
}
];
graph.plotOptions = {
series: {
marker: {
enabled: false,
symbol: "circle"
},
animation: false
}
};
$("#graph-container").highcharts(graph);
}