import toxi.color.*;
import toxi.math.*;
import toxi.math.noise.*;
import toxi.physics.*;
import toxi.physics.behaviors.*;
import controlP5.*;
import toxi.geom.mesh.*;
import java.util.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.math.noise.*;
import toxi.physics.*;
import toxi.physics.behaviors.*;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.util.Calendar;
import toxi.processing.*;
//------------------Import Mode Libraries----------------------
import creeper_Behavior_P3_Solo.*;
import java.util.List;
//----------------------ClassVariables-------------------------
List<Creeper> creeperFamily;
Creeper creeper;
//-----------------CONTROL P5 UI-----------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
boolean showGUI = false;
//Define Global Variables---------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
boolean simulate = true;
//Define Parameters---------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
int resetCounter = 0;
float connectivityThreshold = 0;
float Speed = 0.5;
float SearchRadius = 100;
float AlignValue = 0.25;
float SeparateValue = 100.0;
float CohesionValue = 0.35;
float HeadWidth = 3.0;
float StrokeWidth = 1.0;
float Transparency = 255.0;
float Count = 500;
boolean Connect = false;
boolean Swarm = false;
boolean Perlin = false;
boolean Hybrid = false;
boolean Bounds = false;
int TrailResolution = 6;
float Multiplier = 1.0;
float Scale, Strength, Velocity;
boolean mapVal = false;
boolean ShowMap = false;
boolean ApplyMap = false;
boolean ApplySweetColor = false;
boolean RESET = false;
RadioButton spawn, behavior, dimension;
Knob Blend, MSpeed, MBaseSpeed;
CheckBox checkFlockBox, checkPerlinBox;
PImage img;
Culebra_Interface cI;
void settings() {
size(1400, 1000, FX2D);
smooth();
}
void setup() {
if (this.resetCounter == 0) {
cI = new Culebra_Interface(this, 400, 1025);
}
surface.setLocation(420, 10);
frameRate(100);
img = loadImage("MAP.jpg");
simulate = true;
creeperFamily = new ArrayList<Creeper>();
for (int i = 0; i < Count; i++) {
PVector origin = new PVector();
PVector speed = new PVector();
if (spawn == null || spawn.getState(0)) {
origin = new PVector(0, random(height), 0);
speed = new PVector(random(0, Speed), 0, 0);
} else if (spawn != null || spawn.getState(1)) {
origin = new PVector(random(width), random(height), 0);
speed = new PVector(random(-Speed, Speed), random(-Speed, Speed), 0);
}
this.creeper = new Creeper(origin, speed, width, height);
this.creeperFamily.add(creeper);
}
}
void draw() {
background(0);
if (mapVal == true) {
image(img, 0, 0);
}
this.Speed = this.MBaseSpeed.getValue();
if (behavior.getState(0)) {
this.Swarm = true;
this.Perlin = false;
}
if (behavior.getState(1)) {
this.Perlin = true;
this.Swarm = false;
this.Hybrid = false;
}
if (behavior.getState(2)) {
this.Perlin = false;
this.Swarm = false;
this.Hybrid = true;
}
if (!behavior.getState(0)) {
this.Swarm = false;
}
if (!behavior.getState(1)) {
this.Perlin = false;
}
if (!behavior.getState(2)) {
this.Hybrid = false;
}
for (int i = 0; i < creeperFamily.size (); i++) {
Creeper creep = (Creeper)creeperFamily.get(i);
creep.applyColor = this.ApplySweetColor;
creep.applyMap = this.ApplyMap;
creep.img = this.img;
creep.searchRad = SearchRadius;
creep.av = AlignValue;
creep.sv = SeparateValue;
creep.cv = CohesionValue;
creep.swarm = Swarm;
creep.perlin = Perlin;
creep.bounds = Bounds;
creep.multiplier = this.Multiplier;
creep.scale = this.Scale;
creep.strength = this.Strength;
creep.velocity = this.Velocity;
creep.blend = this.Blend.getValue();
creep.max = this.MSpeed.getValue();
creep.hybrid = this.Hybrid;
creep.strokeWidth = StrokeWidth;
creep.transparency = Transparency;
creep.simulate = simulate;
creep.trailResolution = TrailResolution;
creep.creeperCollection = this.creeperFamily;
if (this.ApplyMap) {
creep.mapAV = this.checkFlockBox.getState(0);
creep.mapSV = this.checkFlockBox.getState(1);
creep.mapCV = this.checkFlockBox.getState(2);
creep.mapPS = this.checkPerlinBox.getState(0);
creep.mapPSC = this.checkPerlinBox.getState(1);
creep.mapPM = this.checkPerlinBox.getState(2);
}
creep.action();
pushStyle();
stroke(255, 255, 255); //Stroke Value
strokeWeight(HeadWidth); //ThickLines
point(creep.loc.x, creep.loc.y, 0);
popStyle();
noFill();
if (i!=0) {
if (creep.trailData.size() > 0) {
for (int rr = 0; rr < creep.trailData.size (); rr++) {
List<PVector> vecs = creep.trailData.get(rr);
ArrayList colors = new ArrayList();
if (this.ApplySweetColor) {
colors = creep.trailColors.get(rr);
}
PVector vecA = vecs.get(0);
PVector vecB = vecs.get(1);
if (this.ApplySweetColor) {
Float val = (Float) colors.get(0);
int val2 = (Integer) colors.get(1);
Float val3 = (Float) colors.get(2);
strokeWeight(val);
stroke(val2, val3);
} else {
strokeWeight(1);
stroke(255, 255);
}
line(vecA.x, vecA.y, vecB.x, vecB.y);
}
}
}
}
}
void RESET(boolean resetFlag) {
if (resetFlag) {
this.resetCounter ++;
setup();
}
}
void ShowMap(boolean theFlag) {
if (theFlag==true) {
mapVal = true;
} else {
mapVal = false;
}
}
void keyPressed() {
if (key == 's') {
simulate = !simulate;
}
if (key == 'r') {
setup();
}
}
Update