int position; Sperm s[]; int num; float newTime,oldTime,diffTime; float toggle; float moveX, moveY; Vec2D mouseMoved; void setup() { size(500,500); background (240,170,216); smooth(); position=0; num = 50; oldTime=0; newTime=0; toggle=1; mouseMoved = new Vec2D(0,1); s = new Sperm[num]; for (int i=0; i width) pos.x = 0; else if (pos.x < 0) pos.x = width; if (pos.y > height) pos.y = 0; else if (pos.y < 0) pos.y = height; } } // General vector class for 2D vectors class Vec2D { float x,y; // Constructor with no parameters Vec2D() { x=0; y=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; } }