class Hair { private float HAIR_LENGTH = 15; private float ALIGNMENT = 0.15; private float x0, y0; private float x1, y1; private float newX1, newY1; private int indexX = 0, indexY = 0; private color col = color(0,0,0,64); Hair(float _x, float _y, int ix, int iy) { x0 = _x; y0 = _y; indexX = ix; indexY = iy; randomizeDirection(); } Hair(float _x, float _y, int ix, int iy, float alignment, float hairLength) { this(_x,_y,ix,iy); ALIGNMENT = alignment; HAIR_LENGTH = hairLength; } Hair(float _x0, float _y0, float _x1, float _y1,int ix, int iy, float alignment, float hairLength) { x0 = _x0; y0 = _y0; x1 = _x1; y1 = _y1; indexX = ix; indexY = iy; ALIGNMENT = alignment; HAIR_LENGTH = hairLength; } public Hair clone() { Hair h = new Hair(x0,y0,x1,y1,indexX,indexY,ALIGNMENT,HAIR_LENGTH); return h; } public void randomizeDirection() { float rotation = random(TWO_PI); x1 = x0 + HAIR_LENGTH*cos(rotation); y1 = y0 + HAIR_LENGTH*sin(rotation); newX1 = x1; newY1 = y1; } public float getDirX() { return (x1-x0); } public float getDirY() { return (y1-y0); } public void setDirX(float dx) { x1 = dx + x0; } public void setDirY(float dy) { y1 = dy + y0; } public void setAlignment(float a) { ALIGNMENT = a; } public void setLength(float v) { HAIR_LENGTH = v; } void addNewDir(float dx, float dy, float strength) { float newDirX = (newX1-x0) + dx*strength; float newDirY = (newY1-y0) + dy*strength; // normalize: float newLen = sqrt(sq(newDirX)+sq(newDirY)); float nFac = HAIR_LENGTH/newLen; newDirX *= nFac; newDirY *= nFac; newX1 = x0 + newDirX; newY1 = y0 + newDirY; } void makeNewDirection(Hair[][] h) { int nrOfNeighbours = 0; float totalDirX=0, totalDirY=0; for (int xo=-1;xo<=1;xo++) for (int yo=-1;yo<=1;yo++) { int nx = indexX + xo, ny = indexY + yo; if (nx<0) nx+=h.length; if (nx>=h.length) nx-=h.length; if (ny<0) ny+=h[0].length; if (ny>=h[0].length) nx-=h[0].length; if (nx>=0&&nx=0&&ny