class Cell{ int alive, crowded; float xpos, ypos, direction, energy, weight; float speed = .1; int maxenergy = int(random(20))+50; color colour; Cell (int _a, float _e, float _xpos, float _ypos, float _d, color _c){ alive = _a; energy = _e; xpos = _xpos; ypos = _ypos; direction = _d; colour = _c; } void move(){ if(mousePressed){ formation=true; } else { formation = false; } if(!formation){ direction+=(random(PI/8)-PI/16); } else { direction=(atan2(ypos-mouseY,xpos-mouseX))+PI; direction+=random(PI/25)-(PI/50); } xpos+=cos(direction)*speed; ypos+=sin(direction)*speed; if(sqrt(sq(xpos-width/2)+sq(ypos-height/2))>width/2.2){ xpos=width/2+cos(atan2(ypos-height/2,xpos-width/2))*(width/2.2-1); ypos=height/2+sin(atan2(ypos-height/2,xpos-width/2))*(height/2.2-1); crowded++; } } void hitTest(){ for(int j=0; jmaxenergy){ for(int j=0; jmaxenergy){ energy=maxenergy; } if(energy<10){ energy=0; alive=0; numOfCells--; } weight=energy/5+2; } void update(){ strokeWeight(1); stroke(0); fill(colour,150); ellipse(xpos,ypos,weight,weight); stroke(0,150); fill(255,150); ellipse(xpos,ypos,weight/2,weight/2); } }