/////////////////////////////////////////////////////////////////////////////////////
import toxi.color.*;
import toxi.math.*;
import controlP5.*;
import java.util.*;
import toxi.geom.*;
//-------------------------------------------------------------------------------------------
int resetAmount = 0;
float objectCount = 1000;
float sepVal, neighborDist, aligVal, cohVal, maxSpeed, maxSep, initSpeed,spawnEdge;
//-------------------------------------------------------------------------------------------
boolean valfromMap,showMap,SpawnEdge,simulate;
boolean setMap = false;
//-------------------------------------------------------------------------------------------
GUI cgui;
PImage img;
//-------------------------------------------------------------------------------------------
ArrayList group;
//-------------------------------------------------------------------------------------------
//---------------------------------------Settings--------------------------------------------
//-------------------------------------------------------------------------------------------
void settings() {
size(1800, 1000, FX2D);
smooth();
}
//---------------------------------------Setup-----------------------------------------------
//-------------------------------------------------------------------------------------------
void setup() {
background(0);
simulate = true;
if (this.resetAmount == 0) {
cgui = new GUI();
cgui.run(this);
}
img = loadImage("MAP3.jpg");
frameRate(100);
this.group = new ArrayList();
//-------------------------------------------------------------------------------------------
for (int i = 0; i < objectCount; i ++) {
Vec3D initVel, agLoc;
if (!this.SpawnEdge) { // set init spawn and speed based on spawning on edge
agLoc = new Vec3D(random(width), random(height), 0);
initVel = new Vec3D(random(-initSpeed, initSpeed), random(-initSpeed, initSpeed), 0);
} else { //spawn randomly and move randmly
agLoc = new Vec3D(random(0), random(height), 0);
initVel = new Vec3D(1, 0, 0);
}
Meanderer obj = new Meanderer(agLoc, initVel);
group.add(obj);
}
}
//---------------------------------------Draw------------------------------------------------
//-------------------------------------------------------------------------------------------
void draw() {
background(0);
//-------------------Set the field values for the meanderer--------------------------------
this.initSpeed = this.cgui.is.getValue();
this.objectCount = this.cgui.ac.getValue();
for (int i = 0; i < this.group.size(); i++) {
Meanderer obj = (Meanderer) this.group.get(i);
obj.MaxForce = this.cgui.mf.getValue();
obj.MaxSpeed = this.cgui.ms.getValue();
obj.Multiplier = this.initSpeed;
obj.randomize = this.cgui.rc.getState();
obj.wandertheta = this.cgui.wt.getValue();
obj.wanderR = this.cgui.wr.getValue();
obj.wanderD = this.cgui.wd.getValue();
obj.change = this.cgui.wc.getValue();
obj.run();
}
if (showMap == true) {
image(img, 0, 0);
tint(255, 120);
}
}
//---------------------------------------Keys------------------------------------------------
//-------------------------------------------------------------------------------------------
void keyPressed() {
if (key == 'R') {
this.resetAmount ++;
setup();
}
if (key == 'U') {
simulate = !simulate;
}
if (key == 'S') {
showMap = !showMap;
}
if (key == 'A') {
setMap = !setMap;
}
if (key == 'P') {
simulate = !simulate;
saveFrame("img-######.png");
}
}
Update