int n= 3000; boolean alive= true; fly[] a= new fly[n]; void setup(){ size(250, 250); stroke(100); colorMode(HSB); for(int i= 0; i0){ f.x+= xnext; } else{ f.x-= xnext; } if(height/2+f.y+xnext0){ f.y+= ynext; } else{ f.y-= ynext; } stroke(150); point(f.x, f.y); } } // General vector class for 2D vectors class Vec2D { float x,y; 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 getlength() { return sqrt(x*x+y*y); } float angle() { return atan2(y,x); } void normalise() { float l=getlength(); 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; } }