This repository was archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
126 lines (102 loc) · 3.38 KB
/
sketch.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
let programRunning = true;
let simulationSize;
let deathrate;
let infectionrate;
let circleSize;
let amountOfFools;
let movementType;
let collisionType;
let countCOLLISION = 0;
let countINFECTIONS = 0;
let healthyPeople;
let sickPeople;
let curedPeople;
let deadPeople;
let sim;
let addDataGraphTimer;
function setup() {
updateTextValueFromSlider();
var canvas = createCanvas(getSketchWidth(), 440);
// Move the canvas so it’s inside our <div id="sketch-holder">.
canvas.parent('sketch-holder');
startProgram();
addDataGraphTimer = new Timer(1000);
}
function draw() {
// normal code
if (programRunning) {
background(52, 58, 64);
sim.move();
if (collisionType == "optionOthersCollision") { sim.simpleCollision(); }
if (collisionType == "optionOurCollision") { sim.advancedCollision(); }
// sim.highlightMouseCell();
sim.display();
countInformation();
updateStatistics();
} else {
background(200, 20, 20);
getUserInput();
let squareGridWidth = sqrt((height * width) / simulationSize);
let rows = floor(height / squareGridWidth);
let cols = floor(width / squareGridWidth);
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
let pointNumber = (i)*cols+(j);
if (pointNumber < amountOfFools) {
stroke(40, 255, 0);
} else {
stroke(40, 40, 60);
}
strokeWeight(circleSize);
point(j * squareGridWidth + squareGridWidth / 2, i * squareGridWidth + squareGridWidth / 2);
}
}
}
}
function countInformation() {
healthyPeople = 0;
sickPeople = 0;
curedPeople = 0;
deadPeople = 0;
for (let person of sim.listOfPersons) {
if (person.alive && !person.infected) { healthyPeople++; }
else if (person.alive && person.infected) { sickPeople++; }
else if (person.alive && person.cured) { curedPeople++; }
else if (!person.alive) { deadPeople++; }
else { print("Det er sket en ukendt fejl og du burde kontakte PET for hjælp."); }
}
if (addDataGraphTimer.timerRunOut()) {
updateGraph();
addDataGraphTimer.start();
}
}
function updateStatistics() {
let healthyPeopleText = document.getElementById("healthyPeopleText");
let sickPeopleText = document.getElementById("sickPeopleText");
let curedPeopleText = document.getElementById("curedPeopleText");
let deadPeopleText = document.getElementById("deadPeopleText");
healthyPeopleText.innerHTML = healthyPeople;
sickPeopleText.innerHTML = sickPeople;
curedPeopleText.innerHTML = curedPeople;
deadPeopleText.innerHTML = deadPeople;
}
function windowResized() {
resizeCanvas(getSketchWidth(), 440);
}
function getSketchWidth() {
let myWindowWidth = document.getElementById("sketch-width").clientWidth;
print("Width of canvas should be : " + myWindowWidth);
return myWindowWidth;
}
class Timer {
constructor(seconds) {
this.maxTime = seconds;
this.start();
}
start() {
this.startTime = millis();
}
timerRunOut() {
return (millis() > this.startTime+this.maxTime);
}
}