Skip to content

Commit 9edbf39

Browse files
authored
fix issue with reload button and onChange event
1 parent ec5b14a commit 9edbf39

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

sketch.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class person_C {
5252

5353
class People_C {//constructor
5454
//the Peoples
55-
constructor(nb_rows, nb_cols) {
55+
constructor(nb_rows, nb_cols,PROBA_DEATH,CONTAGION_RATE,PROBA_INFECT,VACCINATION_RATE) {
5656
this.nb_rows = nb_cols;
5757
this.nb_cols = nb_cols;
5858
this.all = new Array();
@@ -229,12 +229,12 @@ const random = (a) => Math.floor(Math.random() * a);
229229
const sliderWidth = 200;
230230
const sliderHeight = 50;
231231

232-
let People = new People_C(20, 20)
233232
const PROBA_DEATH_callBack = (e) => {//constructor
234233
PROBA_DEATH_Value.innerText = e.value;
235234
console.log("TCL: PROBA_DEATH_callBack -> e.value", Number(e.value))
236-
237-
People.set("PROBA_DEATH", Number(e.value))
235+
PROBA_DEATH=Number(e.value)
236+
People.set("PROBA_DEATH", Number(e.value));
237+
setup();
238238
}
239239

240240

@@ -243,20 +243,24 @@ const VACCINATION_RATE_callBack = (e) => {//constructor
243243
document.getElementById('VACCINATION_RATE_Value').innerText = e.value;
244244
document.getElementById('VACCINATION_RATE_Value').value = e.value;
245245

246-
People.set("VACCINATION_RATE", Number(e.value))
246+
VACCINATION_RATE=Number(e.value)
247+
People.set("VACCINATION_RATE", Number(e.value));
248+
setup();
247249
}
248250
const CONTAGION_RATE_callBack = (e) => {//constructor
249251

250252
CONTAGION_RATE_Value.innerText = e.value;
251-
253+
CONTAGION_RATE=Number(e.value)
254+
PROBA_INFECT=Number(e.value)
252255
People.set("CONTAGION_RATE", Number(e.value))
253256
People.set("PROBA_INFECT", Number(e.value) * 10)
257+
setup();
254258

255259
}
256260

257261

258262
function setup() {
259-
People = new People_C(20, 20)
263+
People = new People_C(20, 20,PROBA_DEATH,CONTAGION_RATE,PROBA_INFECT,VACCINATION_RATE)
260264

261265
createCanvas(800, 800);
262266
People.init();
@@ -281,4 +285,4 @@ function run() {
281285

282286
function reload() {
283287
setup();
284-
}
288+
}

0 commit comments

Comments
 (0)