forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChemotaxis.pde
66 lines (59 loc) · 1.04 KB
/
Chemotaxis.pde
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
Bacteria[] blob;
void setup() {
size(500, 500);
frameRate(10);
blob = new Bacteria[100];
for (int i = 0; i < blob.length; i++) {
blob[i] = new Bacteria();
}
}
void draw() {
background(150);
for (int i = 0; i < blob.length; i++) {
blob[i].show();
blob[i].move();
}
}
class Bacteria {
int myX;
int myY;
int mySize;
int myColor;
Bacteria(){
myX = x;
myY = y;
mySize = 25;
myColor = color((int)(Math.random()*27) + 72, (int)(Math.random()*30) + 162, (int)(Math.random()*55) + 16);
//popped = false;
}
int x;
int y;
void move(){
int direction = (int)(Math.random()*4);
if (direction == 0){
x = x + 20;
}
else if (direction == 1){
x = x - 20;
}
else if (direction == 2){
y = y + 20;
}
else{
y = y - 20;
}
if (x < 0 || x > 500){
x = 250;
y = 250;
}
if (y < 0 || y > 500){
x = 250;
y = 250;
}
}
void show(){
noStroke();
fill(myColor);
ellipse(x, y, mySize, mySize);
}
}