genome gene; float mx; void setup() { size(300,300); ellipseMode(CENTER_DIAMETER); gene=new genome(); // gene.printGenome(); } void loop() { background(80); mx=mx+getSpringForceScalar(mx,constrain(mouseX,0,200),0,.2); translate(0,0,constrain(mx,0,300)); drawPhenome(gene); } void mouseReleased() { setup(); } void drawPhenome(genome g) { noStroke(); fill(208,25,15); position rootPos=new position(width/2,height/2); ellipse(rootPos.x,rootPos.y,3,3); for(int v=0;v0) { for(int i=0;i0) // { if(s.y>testY) return 1; else return -1; /* } else { if(s.y>testY) return -1; else return 1; }*/ } } position displace(position p,float angle,float magnitude) //displaces a position by an angle and a magnitude, then returns it { position newP=new position(p); float ra=radians(angle); newP.x+=(cos(ra)*magnitude); newP.y-=(sin(ra)*magnitude); return newP; } float getHeading(position p1,position p2) //gets the absolute heading between one position and another relative to the first { if(p1.x==p2.x&&p1.y==p2.y) return 0; float xd=p2.x-p1.x; float yd=p2.y-p1.y; float angle=float(Math.atan(yd/xd)); // angle=degrees(angle); angle=angle*conversionArc; if(xd>0&&yd<0) { angle=-1*angle; } else if(xd<0&&yd<0) angle=180-angle; else if(xd<0&&yd>0) angle=180-angle; else if(xd<0&&yd==0) angle=180; else if(xd==0&&yd<0) angle=90; else angle=360-angle; return angle; } float dist(position p1,position p2) { return dist(p1.x,p1.y,p2.x,p2.y); } float normalizeHeading(float ang) //normalizes a heading between 0 and 360 { while(ang > 360)ang -= 360; while(ang < 0)ang += 360; return ang; } void drawVector(vector v) //draws a vector in white { colorMode(RGB,255,255,255); stroke(255); noFill(); ellipseMode(CENTER_DIAMETER); ellipse(v.p.x,v.p.y,5,5); position e=v.endPoint(); line(v.p.x,v.p.y,e.x,e.y); } void drawVector(vector v,float s) //draws a vector with a longer line for representation in white { colorMode(RGB,255,255,255); stroke(255); noFill(); ellipseMode(CENTER_DIAMETER); ellipse(v.p.x,v.p.y,5,5); vector temp=new vector(v); temp.m*=s; position e=temp.endPoint(); line(temp.p.x,temp.p.y,e.x,e.y); } void drawVector(vector v,int r,int g,int b,float s) //draws a vector with a longer line for representation in white { colorMode(RGB,255,255,255); stroke(r,g,b); noFill(); ellipseMode(CENTER_DIAMETER); ellipse(v.p.x,v.p.y,5,5); vector temp=new vector(v); temp.m*=s; position e=temp.endPoint(); line(temp.p.x,temp.p.y,e.x,e.y); } void drawVector(vector v,int r,int g,int b) //draws a vector in RGB { colorMode(RGB,255,255,255); stroke(r,g,b); noFill(); ellipseMode(CENTER_DIAMETER); ellipse(v.p.x,v.p.y,5,5); position e=v.endPoint(); line(v.p.x,v.p.y,e.x,e.y); } void printFloat(String s, float z) { print(s); print(": "); println(z); return; } void printPos(String s,position p) { print(s+" coordinates (x:"); println(p.x+","+p.y+")"); return; }