forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chemotaxis.pde
45 lines (45 loc) · 888 Bytes
/
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
Bacteria [] dots;
void setup() {
size(500, 500);
background(0);
dots = new Bacteria[20];
for(int i = 0; i < dots.length;i++)
{
dots[i] = new Bacteria();
}
}
void draw() {
for(int i = 0; i < dots.length;i++) {
dots[i].walk();
dots[i].show();
}
}
class Bacteria {
int x, y, myColorR, myColorG, myColorB;
Bacteria() {
x = 250;
y = 250;
myColorR = (int)(Math.random()*79)+176;
myColorG = (int)(Math.random()*79)+176;
myColorB = (int)(Math.random()*79)+176;
}
void walk() {
int direction = (int)(Math.random()*4);
if (direction == 0) {
x = x + 20; //right
}
else if (direction == 1) {
x = x - 20; //left
}
else if (direction == 2) {
y = y + 20; //down
}
else {
y = y - 20; //up
}
}
void show() {
fill(myColorR, myColorG, myColorB);
ellipse(x, y, 50, 50);
}
}