Skip to content

Commit 4ce79f3

Browse files
authored
Add 2 input to User interface,update sketch
//Fix the issue 'y2 don't exist' if the number of rows and column different. //Add 2 input to User interface to change the number rows and column
1 parent 9edbf39 commit 4ce79f3

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

sketch.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ let conti = false;
66
let VACCINATION_RATE = 50
77
let SIMULATION_SPEED = 25 // time between days in milliseconds. 0: fastest.
88
// 500 means every day the simulation pauses for 500 //25 is good for watching
9-
const nb_rows = 50;
10-
const Rayon = 20;//Rayon of circle
9+
let nb_rows = 50;
10+
let nb_cols = 50;
11+
let Rayon = 20;//Rayon of circle
1112
const colors = {
1213
WHITE: [255, 255, 255],
1314
BLUE: [0, 0, 255],
@@ -53,7 +54,7 @@ class person_C {
5354
class People_C {//constructor
5455
//the Peoples
5556
constructor(nb_rows, nb_cols,PROBA_DEATH,CONTAGION_RATE,PROBA_INFECT,VACCINATION_RATE) {
56-
this.nb_rows = nb_cols;
57+
this.nb_rows = nb_rows;
5758
this.nb_cols = nb_cols;
5859
this.all = new Array();
5960
this.Default_X = Rayon;
@@ -70,7 +71,7 @@ class People_C {//constructor
7071
}
7172
set(arg, value) {
7273
this[arg] = value;
73-
console.log(this[arg])
74+
// console.log(this[arg])
7475

7576
}
7677
init() {
@@ -93,7 +94,7 @@ class People_C {//constructor
9394

9495
//55=10
9596

96-
console.log(this.all)
97+
// console.log(this.all)
9798
}
9899
draw() {
99100
// console.log(this.all)
@@ -153,7 +154,7 @@ class People_C {//constructor
153154
let a = random(this.nb_rows), b = random(this.nb_cols)
154155
const patientZero = this.all[a][b].sick
155156
this.vaccinate()
156-
console.log("TCL: People_C -> spreadDisease -> patientZero", a, b)
157+
// console.log("TCL: People_kC -> spreadDisease -> patientZero", a, b)
157158
if (this.all[a][b].Vaccinate) return People.spreadDisease()
158159
this.all[a][b].sick = 10;
159160
this.NBInfected++
@@ -180,7 +181,7 @@ class People_C {//constructor
180181

181182
this.all[r][c].sick++;
182183
if (this.all[r][c].sick >= 20) {
183-
console.log(this.PROBA_DEATH)
184+
// console.log(this.PROBA_DEATH)
184185
if (random(99) < this.PROBA_DEATH) {
185186
// console.log("TCL: People_C -> spreadDiksease -> person dead");
186187
this.all[r][c].dead = true;
@@ -194,13 +195,14 @@ class People_C {//constructor
194195
}
195196

196197
}
197-
console.log(this.all[r][c].Vaccinate)
198+
// console.log(thkis.all[r][c].Vaccinate)
198199
if (!this.all[r][c].dead && !this.all[r][c].Vaccinate && random(99) < this.PROBA_INFECT) {
199200

200201
neighbour = this.get_neighbour(r, c)
201202
x2 = neighbour[0]
202203
y2 = neighbour[1]
203-
if (!this.all[x2][y2].Vaccinate && this.all[x2][y2].sick === 0 && this.all[x2][y2]) {
204+
//fix the issue with the y2 don't exist if we select the Nomber of rows and column is different.
205+
if (this.all[x2]&&!this.all[x2][y2].Vaccinate && this.all[x2][y2].sick === 0 && this.all[x2][y2]) {
204206
this.all[x2][y2].sick = 10;
205207
this.NBInfected = this.NBInfected + 1
206208

@@ -231,7 +233,7 @@ const sliderHeight = 50;
231233

232234
const PROBA_DEATH_callBack = (e) => {//constructor
233235
PROBA_DEATH_Value.innerText = e.value;
234-
console.log("TCL: PROBA_DEATH_callBack -> e.value", Number(e.value))
236+
// console.log("TCL: PROBA_DEATH_callBack -> e.value", Number(e.value))
235237
PROBA_DEATH=Number(e.value)
236238
People.set("PROBA_DEATH", Number(e.value));
237239
setup();
@@ -257,12 +259,18 @@ const CONTAGION_RATE_callBack = (e) => {//constructor
257259
setup();
258260

259261
}
260-
262+
function setCell(e,type){
263+
switch(type){
264+
case 'row':nb_rows = +e.value;break;
265+
case 'column':nb_cols = +e.value;break;
266+
}
267+
setup();
268+
}
261269

262270
function setup() {
263-
People = new People_C(20, 20,PROBA_DEATH,CONTAGION_RATE,PROBA_INFECT,VACCINATION_RATE)
271+
People = new People_C(nb_rows, nb_cols,PROBA_DEATH,CONTAGION_RATE,PROBA_INFECT,VACCINATION_RATE)
264272

265-
createCanvas(800, 800);
273+
createCanvas(nb_rows*Rayon*3, nb_cols*Rayon*3);
266274
People.init();
267275
People.draw();
268276

@@ -274,12 +282,12 @@ function draw() {
274282
background(255);
275283
People.spreadDisease(People);
276284
People.draw()
277-
console.log(People.PROBA_DEATH)
285+
// console.log(People.PROBA_DEATH)
278286
}
279287
function run() {
280288
conti = true
281289

282-
console.log("TCL: run -> run")
290+
// console.log("TCL: run -> run")
283291
loop();
284292
}
285293

0 commit comments

Comments
 (0)