Skip to content

Commit

Permalink
Update Chemotaxis.pde
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyBoy407 authored Oct 23, 2024
1 parent 1b0256e commit 8b89514
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions Chemotaxis.pde
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
//declare bacteria variables here
void setup()
{
//initialize bacteria variables here
}
void draw()
{
//move and show the bacteria
}
class Bacteria
{
//lots of java!
}
Walker [] bob = new Walker[100];
void setup(){
size(400,400);
for(int i = 0; i < bob.length; i++){
bob[i] = new Walker((int)(Math.random()*width), (int)(Math.random()*height));
}
}

void draw(){
background(154);
for(int i = 0; i < bob.length; i++){
bob[i].walk();
bob[i].show();
}
}

class Walker{
int myX, myY, myColor;
Walker(int x, int y){
myX = x;
myY = y;
myColor = color(255,0,0);
}
void walk(){
if (mouseX > myX){
myX = myX + (int)(Math.random()*5)-1;
}
else{
myX = myX + (int)(Math.random()*5)-3;
}
if (mouseY > myY){
myY = myY + (int)(Math.random()*5)-1;
}
else{
myY = myY + (int)(Math.random()*5)-3;
}
if(mousePressed){
myX = (int)(Math.random()*width);
myY = (int)(Math.random()*height);
}
}
void show(){
fill(myColor);
ellipse(myX,myY,20,20);
}
}

0 comments on commit 8b89514

Please sign in to comment.