-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
52 lines (41 loc) · 991 Bytes
/
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
var population = 100;
var R = 3;
var immunityChance = 5;
var people = [];
var rslider;
var islider;
var pslider;
function setup() {
createCanvas(640, 360);
pslider = createSlider(50, 250, 100, 1);
rslider = createSlider(0.9, 5, 2.5, 0.5);
islider = createSlider(2, 10, 5, 1);
}
function keyPressed() {
if (keyCode == ENTER) {
people.splice(0, 250);
for (let i = 0; i < pslider.value(); i++) {
people.push(new Subject(rslider.value(), islider.value()));
}
}
}
function draw() {
background(51);
for (let i = 0; i < people.length; i++) {
people[i].show();
people[i].update();
for (let j = 0; j < people.length; j++) {
people[i].infection(people[j]);
people[i].bounceOff(people[j]);
}
}
textSize(10);
fill(255);
text("population: " + pslider.value(), 35, 350);
textSize(10);
fill(255);
text("R: " + rslider.value(), 190, 350);
textSize(10);
fill(255);
text("immunity: " + islider.value(), 305, 350);
}