// by stephan schulz Vec2D v[],v2[]; int num=10; float orgSize; void setup() { size(400,200); orgSize = (float)width/(float)num; v=new Vec2D[num]; v2=new Vec2D[num]; for(int i=0; i0) { v[i].x = v[i-1].x + v[i-1].w; v[i].y = v[i-1].y; v2[i].x = v2[i-1].x + v2[i-1].w; v2[i].y = height/2-v2[i].w; } else { v[0].x= 0; v[0].y= height/2; v2[0].x= 0; v2[0].y= height/2-v2[0].h; } } } void loop() { background(0,140,255); // fill(12); //rect(0,0,width,height/2); for(int i=0; i orgSize) { int r = (int)random(num); float rand=1; //random(1); v[iSize].w = v[iSize].w - rand; v[iSize].h = v[iSize].w; v[r].w = v[r].w + rand; v[r].h = v[r].w; for(int iPos=0; iPos0) { v[iPos].x = v[iPos-1].x + v[iPos-1].w; v[iPos].y = v[iPos-1].y; } else { v[0].x= 0; v[0].y= height/2; } } } if (v2[iSize].w > orgSize) { int r2 = (int)random(num); float rand2= 1; //random(-1); v2[iSize].w = v2[iSize].w - rand2; v2[iSize].h = v2[iSize].w; v2[r2].w = v2[r2].w + rand2; v2[r2].h = v2[r2].w; for(int iPos=0; iPos0) { v2[iPos].x = v2[iPos-1].x + v2[iPos-1].w; v2[iPos].y = height/2-v2[iPos].w; } else { v2[0].x= 0; v2[0].y= height/2-v2[0].h; } } } } } //void mousePressed() { void mouseMoved() { for(int i=0; i0) { v[i2].x = v[i2-1].x + v[i2-1].w; v[i2].y = v[i2-1].y; v2[i2].x = v2[i2-1].x + v2[i2-1].w; v2[i2].y = height/2-v2[i2].w; } else { v[0].x= 0; v[0].y= height/2; v2[0].x= 0; v2[0].y= height/2-v2[0].h; } } } } // General vector class for 2D vectors class Vec2D { float x,y,h,w; // Constructor with no parameters Vec2D() { x=0; y=0; w=0; h=0; } Vec2D(float _x,float _y) { x=_x; y=_y; } Vec2D(Vec2D v) { x=v.x; y=v.y; } void set(float _x,float _y) { x=_x; y=_y; } void set(Vec2D v) { x=v.x; y=v.y; } void add(float _x,float _y) { x+=_x; y+=_y; } void add(Vec2D v) { x+=v.x; y+=v.y; } void sub(float _x,float _y) { x-=_x; y-=_y; } void sub(Vec2D v) { x-=v.x; y-=v.y; } void mult(float m) { x*=m; y*=m; } void div(float m) { x/=m; y/=m; } float length() { return sqrt(x*x+y*y); } float angle() { return atan2(y,x); } void normalise() { float l=length(); if(l!=0) { x/=l; y/=l; } } Vec2D tangent() { return new Vec2D(-y,x); } void rotate(float val) { // Due to float not being precise enough, double is used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmpx=x*cosval - y*sinval; double tmpy=x*sinval + y*cosval; x=(float)tmpx; y=(float)tmpy; } }