import java.util.List;
import toxi.geom.*;
import controlP5.*;
//-------------------------------------------------------------------------------------------
//---------------------------------------Globals--------------------------------------------
//-------------------------------------------------------------------------------------------
Vec3D locStart;
Agent a;
ControlP5 cp5;
GUI cgui;
Path tempPath;
boolean simulate;
boolean debug = false;
int resetAmount = 0;
int agentCount = 250;
List<Agent> agentList;
//-------------------------------------------------------------------------------------------
//---------------------------------------Settings--------------------------------------------
//-------------------------------------------------------------------------------------------
void settings() {
size(1920, 1080, FX2D);
smooth();
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Setup-----------------------------------------------
//-------------------------------------------------------------------------------------------
void setup() {
background(0);
this.agentList = new ArrayList<Agent>();
this.simulate = true;
if (this.resetAmount == 0) {
this.cgui = new GUI();
this.cgui.run(this);
}
newPath();
for (int i = 0; i < this.agentCount; i ++) {
this.locStart = new Vec3D(0, random(height), 0);
this.a = new Agent(this.locStart);
this.agentList.add(this.a);
}
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Draw------------------------------------------------
//-------------------------------------------------------------------------------------------
void draw() {
background(0);
this.agentCount = (int)this.cgui.s7.getValue();
this.tempPath.display();
this.tempPath.radius = this.cgui.s0.getValue();
for (Agent ag : this.agentList) { //set the agent field values
ag.maxforce = this.cgui.s6.getValue();
ag.max = this.cgui.s5.getValue();
ag.amp = this.cgui.s9.getValue();
ag.vel = this.cgui.s4.getValue();
ag.run();
}
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Create New Path-------------------------------------
//-------------------------------------------------------------------------------------------
void newPath() {
this.tempPath = new Path();
this.tempPath.addPoint(-20, height/2);
this.tempPath.addPoint(random(0, width/2), random(0, height));
this.tempPath.addPoint(random(width/2, width), random(0, height));
tempPath.addPoint(width+20, height/2);
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Keys------------------------------------------------
//-------------------------------------------------------------------------------------------
void keyPressed() {
if (key == 'R') {
this.resetAmount ++;
setup();
}
if (key == 'S') this.simulate = !this.simulate;
if (key == 'W') this.newPath();
if (key == 'Q')this.debug = !this.debug;
if (key == 'S') {
simulate = !simulate;
saveFrame("img-######.png");
}
}
Update