int n= 3000; boolean alive= true; fly[] a= new fly[n]; queen queen= new queen(); void setup(){ size(250, 250); colorMode(HSB); for(int i= 0; ixpos-5 && mouseXypos-5 && mouseY0){ f.x+= xnext; if(queen.ypos+f.y+ynext0){ f.y+= ynext; if(f.getlength()>1.2*l && alive==true) { f.mult(0.99); } if(mousePressed){ Vec2D mouse= new Vec2D(mouseX-queen.xpos, mouseY-queen.ypos); mouse.sub(f); mouse.div(10); f.sub(mouse); } } else{ f.y-= ynext; } } else{ f.x-= xnext; } stroke(100); 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; } }