class snakey extends creature { segment head; segment belly; segment tail; segment body[]; float distance; float muscleTension=0; float spinAng=0; float s; float speed; float headAng; boolean superSnake=false; float jawControl=0; float jawSnap=40; snakey(penStroke ps) { type=5; vec p=new vec(ps.points[ps.points.length-1].p); s=ps.totalLength/1000; if(s>.75) superSnake=true; int sections=int(constrain(round(s*40),3,40)); if(superSnake) sections=int(sections*.9); body=new segment[sections]; speed=ps.averageLength; speed/=9; speed*=speed; speed=constrain(speed,0.01,100); if(superSnake) speed=speed/6; float sz=s; float ratio=.94; if(superSnake) ratio=.95; for(int i=0;i0) { float ang=getAng(sec.p,body[i-1].p); body[i]=new segment(sec.p,sz*=(ratio-(1-this.s)/9),ang); } else { float ang=getAng(findDrawPoint(ps,1-float(1)/body.length).p,sec.p); body[i]=new segment(sec.p,sz*=(ratio-(1-this.s)/9),ang); } } body[0].m1.connectSpringTo(body[0].m3,.8); body[0].m2.connectSpringTo(body[0].m3,.8); body[0].m1.connectSpringTo(body[0].m2,.5); for(int i=1;i=0;s--) { float dt=dist(body[i].p,body[s].p); body[s].m1.connectSpringTo(body[i].m1,dt,k); body[s].m2.connectSpringTo(body[i].m2,dt,k); k*=(k+.1); if(k<.1) break; } } head=body[0]; headAng=getAng(body[1].p,head.p); belly=body[int((body.length-1)/2)]; tail=body[body.length-1]; if(superSnake) { for(int i=0;i98) { jawSnap+=random(80); } } void draw() { if(superSnake) { drawSuperSnake(); return; } body[0].drawHead(spinAng); for(int i=1;i99.6) { if(useWander) { useWander=false; interest=null; /* for(int i=0;i30) { interest=new vec(clist[i].m.p); break; } } if(interest==null) { int rd=int(random(clist.length)); interest=new vec(clist[rd].m.p); }*/ } else { useWander=true; wander=head.p; wanderTarget=head.p; } } if(!useWander) { if(creatureToFollow==null) { for(int i=0;i.1) { stroke(295-240*s); image(segDetail2,origin,r); } stroke(255-120); image(segDetail,origin,r); stroke(255-230); image(segBase,origin,r); if(s>.1) { stroke(255-160); float es=25*sin(sinWave+s*5); ellipse(-73,45,es,es); ellipse(73,45,es,es); } popMatrix(); } void drawSuperHead(float ang) { int r=int(25*s); noFill(); pushMatrix(); translate(p.x,p.y); rotate(radians(90-head)); scale(s); stroke(295-240*s); image(headDetail3,nv(0,0),r); stroke(255-230); image(headDetail2,nv(0,-84),r); stroke(255-120); image(headDetail1,origin,r); stroke(255-230); image(headBase,origin,r+1); stroke(255-160); float es=25*sin(sinWave+s*5); ellipse(-73,45,es,es); ellipse(73,45,es,es); vec spinP=nv(0,-108); translate(spinP.x,spinP.y); rotate(radians(ang)); stroke(255-190+sin(radians(ang))*40); image(spinner,origin,r); popMatrix(); } }