class organism { segment[] seg= new segment[14]; float mx; //initial head's x (used only in initialize function) float my; //intial head's y float v; //randomly set in initialize, sets speed of seeking float vy; //not used currently int numseg; organism(int numseg_, float mx_, float my_, float v_, float vy_) { numseg=numseg_; mx=mx_; my=my_; v=v_; vy=vy_; initialize(); } float getMX() {return mx;} void setMX(float mx_) {mx = mx_;} float getMY() {return my;} void setMY(float my_) {my = my_;} int getNUMSEG() {return numseg;} void setNUMSEG(int numseg_) {numseg = numseg_; checknumseg();} float getNUMX(int i) {return seg[i].getX();} void setNUMX(int i, float x_) {seg[i].setX(x_);} float getNUMY(int i) {return seg[i].getY();} void setNUMY(int i, float y_) {seg[i].setY(y_);} color getNUMC(int i) {return seg[i].getC();} void setNUMC(int i, color c_) {seg[i].setC(color(red(c_),blue(c_),green(c_),alpha(c_)));} //void setC(color c_) {c=color(red(c_),blue(c_),green(c_),alpha(c_));} void checknumseg() { if (numseg>seg.length) {numseg=seg.length;} if (numseg<0) {numseg=0;} }//end function checknumseg void setSEGC(int index, color c_) { if(index0) { seg[index].setC(color(red(c_),blue(c_),green(c_), alpha(c_))); } } void initialize() { v=random(.5,1.7); //all are initialized even if not used for(int i=0; i< seg.length ; i=i+1) { seg[i] = new segment(mx+float(10*i),my,10,5,color(random(0,200),200,random(0,100),150)); } } void render(float ticker) { checknumseg(); for(int i=0; i< numseg; i=i+1) { //render segments seg[i].render(ticker); //renderspine stroke(0); if(i>0) { line(seg[i].getX(),seg[i].getY(),seg[i-1].getX(),seg[i-1].getY()); } noStroke(); } } void seek(float targetx, float targety) { float gx, gy, distm, an; int i; i=0; checknumseg(); if(numseg>0) { //head seeks target gx=seg[i].getX()-targetx; // positive if 1 to the right of 2 gy=seg[i].getY()-targety; //positive if 1 below 2 distm=sqrt(gx*gx+gy*gy); if (distm>10) { an=atan2(gy,gx); seg[i].setX( seg[i].getX()-1*v*cos(an) ); seg[i].setY( seg[i].getY()-1*v*sin(an) ); } //end seeking } if(numseg>1) { //body follows for(i=1;i10) { seg[i].setX( seg[i].getX()-gx*(distm-10)/distm ); seg[i].setY( seg[i].getY()-gy*(distm-10)/distm ); seg[i].setheading(90-an); } } } }//end seek function boolean near(float tx, float ty, float prox) { //if(abs(mx-tx)