forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChemotaxis.pde
58 lines (54 loc) · 957 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
46
47
48
49
50
51
52
53
54
55
56
57
58
//declare bacteria variables here
Bacteria[] go;
void setup()
{
//initialize bacteria variables here
size(500,500);
go = new Bacteria[50];
for(int i = 0; i < go.length; i++){
go[i] = new Bacteria (150,150);
}
}
void draw()
{
//move and show the bacteria
background(0);
for(int i = 0; i < go.length; i++){
go[i].show();
go[i].walk();
}
noStroke();
fill(220,180,100);
ellipse(mouseX,mouseY,15,15);
}
class Bacteria
{
int myColor;
int myX, myY;
Bacteria(int x, int y)
{
myX = x;
myY = y;
myColor = color(255,255,255);
}
void walk()
{
if(mouseX> myX){
myX = myX + (int)(Math.random()*8)-1;
}else{
myX = myX + (int)(Math.random()*8)-7;
}
if(mouseY>myY){
myY = myY + (int)(Math.random()*8)-1;
}
else{
myY = myY + (int)(Math.random()*8)-7;
}
}
void show()
{
fill(myColor);
noStroke();
ellipse(myX,myY,25,25);
}
}