ArrayList<Particle> p = new ArrayList();
PVector tar=new PVector(), tmp;
tmp=new PVector(width/2, height/2);
for (int i = 0; i < num; i++) {
p.add(new Particle(random(width), random(height)));
rect(0, 0, width, height);
for (int i=0; i<p.size(); i++) {
for (int j=i+1; j<p.size(); j++) {
float r = dist(p.get(i).pos.x, p.get(i).pos.y, p.get(j).pos.x, p.get(j).pos.y);
float pot = potential(r, random(.25, .75));
float potX= pot*(p.get(j).pos.x-p.get(i).pos.x)/r;
float potY= pot*(p.get(j).pos.y-p.get(i).pos.y)/r;
float r = dist(p.get(i).pos.x, p.get(i).pos.y, tx, ty);
float pot = potential(r, 2);
float potX= pot*(tx-p.get(i).pos.x)/r;
float potY= pot*(ty-p.get(i).pos.y)/r;
for (int i = 0; i < p.size(); i++) {
ellipse(tmp.x, tmp.y, 6, 6);
if (mouseButton==RIGHT) {
float potential(float rT, float mT) {
return 1000000*mT/pow((rT+100), 2);
float hue, variation, speed, maxSpeed;
ArrayList<Point> history;
int maxSize=10, hueDif=50;
Particle(float x, float y) {
vel = PVector.random2D();
history = new ArrayList();
hue = map(200,0,360,0,1);
variation = random(0.75, 1);
speed = random(0.25, 0.75);
maxSpeed = random(7, 10);
PVector steer = new PVector(tmp.x, tmp.y);
steer.mult(speed*variation);
history.add(new Point(new PVector(pos.x, pos.y), vel));
if (history.size() > 20) {
for (int i=history.size()-1; i>0; i--) {
float h = map(hue,0,1,0,cM);
float w=map(i, history.size(), 0, maxSize, 0)/1.75;
float a=history.get(i).vel.heading();
if (i==history.size()-1) {
vertex(pos.x+(w*cos(a+radians(-90))), pos.y+(w*sin(a+radians(-90))));
vertex(pos.x+((vel.mag()*1.75)*cos(a)), pos.y+((vel.mag()*1.55)*sin(a)));
vertex(pos.x+(w*cos(a+radians(90))), pos.y+(w*sin(a+radians(90))));
curveVertex(pos.x+(w*cos(a+radians(90))), pos.y+(w*sin(a+radians(90))));
curveVertex(history.get(i).loc.x+(w*cos(a+radians(90))), history.get(i).loc.y+(w*sin(a+radians(90))));
for (int i=0; i<history.size(); i++) {
float w=map(i, history.size(), 0, maxSize, 0)/1.75;
float a=history.get(i).vel.heading();
curveVertex(history.get(i).loc.x+(w*cos(a+radians(-90))), history.get(i).loc.y+(w*sin(a+radians(-90))));
if (i==history.size()-1) {
curveVertex(pos.x+(w*cos(a+radians(-90))), pos.y+(w*sin(a+radians(-90))));
vertex(pos.x+(w*cos(a+radians(-90))), pos.y+(w*sin(a+radians(-90))));
if (dist(pos.x, pos.y, tmp.x, tmp.y) < 100) {
PVector loc=new PVector();
PVector vel=new PVector();
Point(PVector L, PVector v) {