-
Notifications
You must be signed in to change notification settings - Fork 1
/
Simulator.js
97 lines (67 loc) · 1.79 KB
/
Simulator.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
class Simulator{
constructor(){
//array of person
this.population = new Array();
//max size population
this.sizepopulation = 200;
//velocity of people mov
this.velocity = 3;
this.hours = 0;
this.currentIndex = 0;
//controlling current datas
this.qtdinfecteds = 0;
this.qtdrecovered =0;
//save historic
this.arrayQtdinfecteds = new Array();
this.arrayQtdrecovered = new Array();
//free, severe, moderate ...
this.mode = "moderate";
//elements html
this.controlHours = window.setInterval( function(){
sim.hours++;
sim.arrayQtdinfecteds[sim.currentIndex++ ] = sim.qtdinfecteds;
sim.arrayQtdrecovered[sim.currentIndex++ ] = sim.qtdrecovered;
}, 30);
}//end constructor
startPopulation(){
for(var i=0; i < this.sizepopulation; i++){
this.population.push( new Person() );
if(this.mode == "severe")
//severe isolation;
if(Math.random() < 0.8){
this.population[i].quarantine = true;
}
if(this.mode == "moderate")
//moderate isolation
if(Math.random() < 0.4){
this.population[i].quarantine = true;
}
}
this.population[0].startCOVID();
this.population[0].quarantine= false;
};
loop(_this){
vis.printDataDOM();
vis.printPersonCanvas();
vis.printDataCanvas();
if(_this.sizepopulation != _this.qtdrecovered){
window.setTimeout( function() {requestAnimationFrame(
function(){
_this.loop(_this);
}
)},
1000/60);
}else{
_this.restartSimulator();
window.setTimeout( function(){ alert("Thanks for visit. Stay in Home!")}, 100);
}
}
restartSimulator(){
this.qtdrecovered = this.sizepopulation;
this.qtdinfecteds = 0;
//restart
for(i=0; i < this.sizepopulation; i++)
population[i].level = 0;
printPersonCanvas();
}
}