int nrOfWindVectors, maxWindVectors; WindVector[] v; int nrOfParticles; Particle[] p; color white, black, blau, rot; // colors void setup() { size(400,400,P3D); background(white); noFill(); ellipseMode(CENTER_RADIUS); white=color(255,255,255); black=color(0,0,0); blau=color(0,0,255); rot=color(255,0,0); nrOfWindVectors=0; maxWindVectors=500; v=new WindVector[maxWindVectors]; float td = 50; for (float x=0;x0) { for (int i=0; i 0..1 -> 1..0.9 } else { stroke(blau); //slowDown=1; } mov=VecMul(slowDown,mov); // xmov*=slowDown; ymov*=slowDown; pos=VecAdd(pos,mov); // x+=xmov; y+=ymov; if (pos.x<=0) { pos.x=-pos.x; mov.x*=-1; } if (pos.x>width) { pos.x=2*width-pos.x; mov.x*=-1; } if (pos.y<=0) { pos.y=-pos.y; mov.y*=-1; } if (pos.y>height) { pos.y=2*height-pos.y; mov.y*=-1; } //pos=VecInScreen(pos); point(pos.x,pos.y); ellipse(pos.x,pos.y,2,2); } } class WindVector { float xs,ys,xe,ye; boolean zero; Vec B, M, Mnorm; WindVector(float x1,float y1,float x2,float y2) { if (x1==x2&&y1==y2) { zero=true; } else { zero=false; xs=x1; ys=y1; xe=x2; ye=y2; B=new Vec(xs,ys); M=new Vec(xe-xs,ye-ys); Mnorm=VecMul(1/dist(xs,ys,xe,ye),M); } } void update() { stroke(black); if (!zero) { ellipse(xs,ys,5,5); line(xs,ys,xe,ye); } } } float distPointToLine(Vec P,Vec B, Vec M) { // SEE DOCUMENTATION: http://www.magic-software.com/Documentation/DistancePointLine.pdf float t0=VecSkalar(M,VecSub(P,B))/VecSkalar(M,M); float D; if (t0<=0) { D=VecLen(VecSub(P,B)); } else if (t0<1) { D=VecLen(VecSub(P,VecAdd(B,VecMul(t0,M)))); } else { D=VecLen(VecSub(P,VecAdd(B,M))); } return D; } // VECTOR MATHEMATICS: // ------------------- class Vec { float x,y; Vec(float x,float y) { this.x=x; this.y=y; } } Vec VecAdd(Vec a, Vec b) { Vec z=new Vec(0,0); z.x=a.x+b.x; z.y=a.y+b.y; return z; } Vec VecSub(Vec a, Vec b) { Vec z=new Vec(0,0); z.x=a.x-b.x; z.y=a.y-b.y; return z; } Vec VecMul(float a, Vec b) { Vec z=new Vec(0,0); z.x=a*b.x; z.y=a*b.y; return z; } float VecSkalar(Vec a, Vec b) { // (len(a)*len(b)*cos(angle between a and b) float z; z=a.x*b.x+a.y*b.y; return z; } float VecLen(Vec a) { float z=sqrt(a.x*a.x+a.y*a.y); return z; } Vec VecInScreen(Vec a) { Vec z=a; while (z.x>width) { z.x-=width; } while (z.x<1) { z.x+=width; } while (z.y>height) { z.y-=height; } while (z.y<1) { z.y+=height; } return z; }