/* rastaCreature - 2008 by Luis Bustamante. Click on the screen to pull its rastas and help relaxing this nervous thing http://protonumerique.net bled -at- protonumerique.net Some parts Recycled from "SonicHair" by Toxi ( http://toxi.co.uk/p5/sonicHair/) */ import noc.*; /*Vector Library by Dan Shiffmann http://www.shiffman.net/teaching/nature/library/ */ Limb[] h; int hCount=0; float xdist=8; float ydist=8; float movement=0.15; float wPos,hPos, zPos; float angle, anglez; float ex,ey,ez; int radius; float xoff = 200.0; float yoff = 0.0; float zoff = 2.0; float xincrement = 0.01; float yincrement = -0.009; float zincrement = 0.01; float n, m, o; float ang=0; float num = 0.1; void setup(){ size(600,600,P3D); wPos=width*0.5; hPos=height*0.5; zPos = 0; ellipseMode(CENTER); rectMode(CORNER); h=new Limb[50]; radius = 23; } void draw(){ background(255); //check state and change movement rate accordingly if(!mousePressed){ xincrement = 0.01; yincrement = -0.009; zincrement = 0.01; } else{ xincrement = 0.0001; yincrement = -0.0009; zincrement = 0.0001; } n = noise(xoff)*width; m = noise(yoff)*height; o = noise(zoff)*600 - 300 ; ex = n; ey = m; ez = o; xoff += xincrement; yoff += yincrement; zoff += zincrement; ///move noisily in a constrained 3D space levitate(n,m,o); translate(wPos,hPos,zPos); ////Start producing Hairs if they aren't there yet if (hCount0) { d=1/d; nx*=d; ny*=d; nz*=d; } // add to vertex list addSegment(x+=seg_len*nx,y+=seg_len*ny,z+=seg_len*nz); } } void addSegment(float x,float y, float z) { vx[nVert]=x; vy[nVert]=y; vz[nVert++]=z; } // align hair to new direction vector // applies smoothness, curling and gravity void update(float nnx,float nny, float nnz) { // increase hair length seg_len+=(max_len-seg_len)*grow_speed; // add new direction to existing vector nx+=nnx; ny+=nny; nz+=nnz; // normalize new vector float d=sqrt(nx*nx+ny*ny+nz*nz); if (d>0) d=(1/d)*seg_len; nx*=d; ny*=d; nz*=d; // iterate and update all vertices with decreasing effect float sm=smoothness*(seg_len/max_len); float grav=0; curlAngle=0; for(int i=1; i