@@ -6,8 +6,9 @@ let conti = false;
6
6
let VACCINATION_RATE = 50
7
7
let SIMULATION_SPEED = 25 // time between days in milliseconds. 0: fastest.
8
8
// 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
11
12
const colors = {
12
13
WHITE : [ 255 , 255 , 255 ] ,
13
14
BLUE : [ 0 , 0 , 255 ] ,
@@ -53,7 +54,7 @@ class person_C {
53
54
class People_C { //constructor
54
55
//the Peoples
55
56
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 ;
57
58
this . nb_cols = nb_cols ;
58
59
this . all = new Array ( ) ;
59
60
this . Default_X = Rayon ;
@@ -70,7 +71,7 @@ class People_C {//constructor
70
71
}
71
72
set ( arg , value ) {
72
73
this [ arg ] = value ;
73
- console . log ( this [ arg ] )
74
+ // console.log(this[arg])
74
75
75
76
}
76
77
init ( ) {
@@ -93,7 +94,7 @@ class People_C {//constructor
93
94
94
95
//55=10
95
96
96
- console . log ( this . all )
97
+ // console.log(this.all)
97
98
}
98
99
draw ( ) {
99
100
// console.log(this.all)
@@ -153,7 +154,7 @@ class People_C {//constructor
153
154
let a = random ( this . nb_rows ) , b = random ( this . nb_cols )
154
155
const patientZero = this . all [ a ] [ b ] . sick
155
156
this . vaccinate ( )
156
- console . log ( "TCL: People_C -> spreadDisease -> patientZero" , a , b )
157
+ // console.log("TCL: People_kC -> spreadDisease -> patientZero", a, b)
157
158
if ( this . all [ a ] [ b ] . Vaccinate ) return People . spreadDisease ( )
158
159
this . all [ a ] [ b ] . sick = 10 ;
159
160
this . NBInfected ++
@@ -180,7 +181,7 @@ class People_C {//constructor
180
181
181
182
this . all [ r ] [ c ] . sick ++ ;
182
183
if ( this . all [ r ] [ c ] . sick >= 20 ) {
183
- console . log ( this . PROBA_DEATH )
184
+ // console.log(this.PROBA_DEATH)
184
185
if ( random ( 99 ) < this . PROBA_DEATH ) {
185
186
// console.log("TCL: People_C -> spreadDiksease -> person dead");
186
187
this . all [ r ] [ c ] . dead = true ;
@@ -194,13 +195,14 @@ class People_C {//constructor
194
195
}
195
196
196
197
}
197
- console . log ( this . all [ r ] [ c ] . Vaccinate )
198
+ // console.log(thkis .all[r][c].Vaccinate)
198
199
if ( ! this . all [ r ] [ c ] . dead && ! this . all [ r ] [ c ] . Vaccinate && random ( 99 ) < this . PROBA_INFECT ) {
199
200
200
201
neighbour = this . get_neighbour ( r , c )
201
202
x2 = neighbour [ 0 ]
202
203
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 ] ) {
204
206
this . all [ x2 ] [ y2 ] . sick = 10 ;
205
207
this . NBInfected = this . NBInfected + 1
206
208
@@ -231,7 +233,7 @@ const sliderHeight = 50;
231
233
232
234
const PROBA_DEATH_callBack = ( e ) => { //constructor
233
235
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))
235
237
PROBA_DEATH = Number ( e . value )
236
238
People . set ( "PROBA_DEATH" , Number ( e . value ) ) ;
237
239
setup ( ) ;
@@ -257,12 +259,18 @@ const CONTAGION_RATE_callBack = (e) => {//constructor
257
259
setup ( ) ;
258
260
259
261
}
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
+ }
261
269
262
270
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 )
264
272
265
- createCanvas ( 800 , 800 ) ;
273
+ createCanvas ( nb_rows * Rayon * 3 , nb_cols * Rayon * 3 ) ;
266
274
People . init ( ) ;
267
275
People . draw ( ) ;
268
276
@@ -274,12 +282,12 @@ function draw() {
274
282
background ( 255 ) ;
275
283
People . spreadDisease ( People ) ;
276
284
People . draw ( )
277
- console . log ( People . PROBA_DEATH )
285
+ // console.log(People.PROBA_DEATH)
278
286
}
279
287
function run ( ) {
280
288
conti = true
281
289
282
- console . log ( "TCL: run -> run" )
290
+ // console.log("TCL: run -> run")
283
291
loop ( ) ;
284
292
}
285
293
0 commit comments