class mush extends creature { vec headP; float headAng=0; float bodyAng=0; float s; float speed; mass head[]=new mass[3]; mass body; vec interest; float sinWave=0; float decayTimer=1; mush(penStroke ps) { type=1; sinWave=random(10); s=ps.totalLength/100; speed=constrain(ps.averageLength/5,0.1,2); head[0]=new mass(findDrawPoint(ps,.99).p); vec p=head[0].p; vec lp=findDrawPoint(ps,.9).p; float ang=getAng(lp,p); head[1]=new mass(newVec(p,ang+150,25*s)); head[2]=new mass(newVec(p,ang-150,25*s)); head[0].connectSpringTo(head[1],.6); head[0].connectSpringTo(head[2],.6); head[1].connectSpringTo(head[2],.6); headP=midPoint(head[1].p,head[2].p); body=new mass(newVec(p,ang+180,40*s)); body.connectSpringTo(head[1],.9); body.connectSpringTo(head[2],.9); body.connectSpringTo(head[0],.8); int tailSegs=int(round(ps.totalLength/5)); tail=new mass[tailSegs]; for(int i=0;i0) tail[i].connectSpringTo(tail[i-1],.8); if(i>1) tail[i].connectSpringTo(tail[i-2],.7); } tail[0].connectSpringTo(body,0,.8); p=new vec(head[0].p); m=head[0]; wanderAngle=wanderAngleDest=ang; headAng=getAng(headP,head[0].p); interest=headP; if(creationInfo) { println("Creature Mush created..."); println(" size: "+s); println(" speed: "+speed); println(" tail segments: "+tailSegs); } } void update() { m=head[0]; if(!killed) { sinWave-=s/7; behavior(); pullHead(interest,.1); } else { if(decayTimer>0) decayTimer-=.005; } if(decayTimer>0) body(); p=new vec(headP); } float flockRadius=40; creature flockList[]; int maxFlockList=10; void flock() { flockList=new creature[0]; for(int i=0;imaxFlockList) break; } if(flockList.length==0) { wander(.5*speed); return; } else { vec c=new vec(); vec avgVel=new vec(); vec keep=new vec(); for(int i=0;i99) useFlock=toggle(useFlock); float returnBuffer=20; if(headP.x>width-returnBuffer||headP.xheight-returnBuffer||headP.y200) { runAwayFrom=null; return; } if(d==0) d=0.0001; vec vf=newVec(360-delta.ang()+random(-30,30),170*s); vec targ=new vec(headP); targ.add(vf); interest=targ; headAng=delta.ang()+random(-30,30); return; } localCreature=new creature[0]; for(int i=0;i0&&random(100)>99) interest=localCreature[int(random(localCreature.length))].p; if(useFlock) { interest=null; flock(); return; } if(dist(interest,headP)>interestDistance||interest==null) { flock(); return; } return; // if(dist(interest,headP)>interestDistance||interest==null||useFlock) // flock(); // else // pullHead(interest,.1); } void pullHead(vec dp,float k) { if(dp==null) return; sfSingle(head[0],new mass(dp),5,k); } void body() { for(int i=0;i