forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChemotaxis.pde
55 lines (53 loc) · 1.01 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
Mover[] eater = new Mover[10];
PImage img;
void setup(){
size(600,600);
background(255);
img = loadImage("newBurger.jpg");
for(int i = 0; i < eater.length;i++)
{
eater[i] = new Mover();
}
}
void draw(){
background(255);
image(img,mouseX,mouseY, width/16, height/16);
//ellipse(150,150, 50, 50);
for(int i = 0; i < eater.length;i++)
{
eater[i].move();
eater[i].show();
}
}
class Mover{
int x, y, myColor;
Mover(){
x = (int) (Math.random()*600);
y = (int) (Math.random()*600);
if(x >300){
myColor = color(255,0,0);
}
if(y>300){
myColor = color(0,100,100);
}
if(x < 300){
myColor= color(255,100,0);
}
}
void move(){
if(mouseX > x)
x = x + (int) (Math.random()*5)-1;
else
x = x + (int) (Math.random() *5) -3;
if(mouseY > y)
y = y + (int) (Math.random()*5)-1;
else
y = y + (int) (Math.random() *5) -3;
}
void show(){
if(dist(x,y,mouseX,mouseY)<25)
myColor = color(0,255,0);
fill(myColor);
ellipse(x,y,30,30);
}
}