//--CULEBRA-V0.09B2-PROCESSING
//--complicitMatter.com--
/////////////////////////////////////////////////////////////////////////////////////
import toxi.color.*;
import toxi.processing.*;
import controlP5.*;
import toxi.geom.*;
import processing.core.PApplet;
import processing.core.*;
import java.util.ArrayList;
import java.util.List;
import peasy.*;
import java.util.Calendar;
import processing.dxf.*;
//------------------Import Culebra Libraries----------------------
import creeper_Behavior_P3_2_3D_SET3.*;
//----------------------Class Variable Declaration-------------------------
Creeper creeper;
Culebra_Interface cf;
List<Creeper> creeperFamily;
List<PVector> totTail;
ToxiclibsSupport gfx;
//Define Parameters---------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
float Blend, MSpeed, MBaseSpeed, Mod_Mult;
float Scale, Strength, Velocity, Multiplier;
float BoundsWidth;
float BoundsHeight;
float BoundsDepth;
float connectivityThreshold, SearchRadius, AlignValue, SeparateValue, CohesionValue, Trail_ViewAngle, Follow_Coh_Range, Follow_Coh_Mag, Follow_Sep_Range, Follow_Sep_Mag, MaxConn, ConnDist;
float HeadWidth, StrokeWidth, Transparency;
float Speed = 0.5f;
float Count = 500.0f;
boolean Connect, Swarm, Perlin, ModifiedPerlin, Mod_Perlin, Dual, Hybrid, Bounds, Mod_Type_0, Mod_Type_1, Mod_Type_2, F_Bounds, Bounce_Rebirth, Boundary, Bounce_Spawn, Tail_Chaser, Enable_Influence;
boolean mapVal, ShowMap, ApplyMap, ApplySweetColor;
boolean RESET, simulate;
boolean BS, BS2, BS3, BS4, BS5, SP, SP2, SP3, D3;
List<Boolean> rebirthType;
boolean D2 = true;
int rCount, TrailResolution;
int camToggle = 0;
RadioButton spawn, behavior, dimension;
CheckBox checkFlockBox, checkPerlinBox;
PImage img;
PeasyCam cam;
CameraState state;
PVector repeller;
PVector seekerTarg = new PVector(600, 200, 0);
PVector seekerTargB = new PVector(200, 600, 0);
float Attraction, Repulsion, Max_Attraction, Max_Repulsion;
TileSaver tiler;
int imageRes = 3;
boolean pFrame = false;
boolean record = false;
//----------------------------------SETTINGS-----------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
void settings() {
//size(1400, 1000, FX2D); USE FOR BETTER PERFORMANCE
size(1000, 1000, P3D);
smooth();
}
//----------------------------------SETUP-----------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
void setup() {
tiler=new TileSaver(this);
totTail = new ArrayList<PVector>();
if (this.rCount == 0) {
this.cf = new Culebra_Interface(this, 620, 1000);
}
surface.setLocation(640, 10);
surface.setResizable(true);
frameRate(100);
this.img = loadImage("MAP.jpg");
if (this.D3 && this.camToggle < 1) {
this.camToggle ++;
cam = new PeasyCam(this, 1500);
cam.setMinimumDistance(100);
cam.setMaximumDistance(10000);
cam.lookAt(this.BoundsWidth/2, this.BoundsDepth/2, this.BoundsHeight/2);
cam.setSuppressRollRotationMode();
gfx = new ToxiclibsSupport(this);
}
this.simulate = true;
creeperFamily = new ArrayList<Creeper>();
for (int i = 0; i < this.Count; i++) {
PVector origin = new PVector();
PVector speed = new PVector();
if (this.D2) {
if (this.SP) {
origin = new PVector(0, random((int)this.BoundsDepth), 0);
speed = new PVector(random(0, this.Speed), 0, 0);
}
if (this.rCount == 0 || this.SP2) {
origin = new PVector(random((int)this.BoundsWidth), random((int)this.BoundsDepth), 0);
speed = new PVector(random(-this.Speed, this.Speed), random(-this.Speed, this.Speed), 0);
}
} else if (this.D3) {
if (this.rCount == 0 || this.SP) {
origin = new PVector(0, random((int)this.BoundsDepth), 0);
speed = new PVector(random(0, this.Speed), 0, random(0, this.Speed));
} else if (this.SP2) {
origin = new PVector(random((int)this.BoundsWidth), random((int)this.BoundsDepth), random((int) this.BoundsHeight));
speed = new PVector(random(-this.Speed, this.Speed), random(-this.Speed, this.Speed), random(-this.Speed, this.Speed));
} else if (this.SP3) {
origin = new PVector(random((int)this.BoundsWidth), random((int)this.BoundsDepth), 0);
speed = new PVector(random(-this.Speed, this.Speed), random(-this.Speed, this.Speed), random(0, this.Speed));
}
}
if (this.D2) {
this.creeper = new Creeper(origin, speed, (int)this.BoundsWidth, (int)this.BoundsDepth);
} else if (this.D3) {
this.creeper = new Creeper(origin, speed, (int)this.BoundsWidth, (int)this.BoundsDepth, (int) this.BoundsHeight);
}
this.creeperFamily.add(creeper);
}
}
//----------------------------------DRAW-----------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
void draw() {
if (tiler==null) return;
tiler.pre();
background(0, 254);
if (this.D3) {
drawExtents();
}
if (mapVal == true) {
image(img, 0, 0);
}
repeller = new PVector(mouseX, mouseY);
this.SP = this.cf.spawn.getState(0); //get align spawn data from controller
this.SP2 = this.cf.spawn.getState(1); //get scattered spawn data from controller
this.SP3 = this.cf.spawn.getState(2); //get scattered spawn data from controller
this.Speed = this.cf.MBaseSpeed.getValue(); //get the base speed set on controller
this.BS = this.cf.behavior.getState(0); //get the behavioral settings from controller - flock
this.BS2 = this.cf.behavior.getState(1); //get the behavioral settings from controller - perlin
this.BS3 = this.cf.behavior.getState(2); //get the behavioral settings from controller - hybrid
this.BS4 = this.cf.behavior.getState(3); //get the behavioral settings from controller - Mod
this.BS5 = this.cf.behavior.getState(4); //get the behavioral settings from controller - Mod
this.D2 = this.cf.dimension.getState(0); //get the 2D dimension setting from controller - 2D
this.D3 = this.cf.dimension.getState(1); //get the 3D dimension setting from controller - 3D
if (this.BS) {
this.Swarm = true;
this.Perlin = false;
this.ModifiedPerlin = false;
this.Dual = false;
}
if (this.BS2) {
this.Perlin = true;
this.Swarm = false;
this.Hybrid = false;
this.ModifiedPerlin = false;
this.Dual = false;
}
if (this.BS3) {
this.Perlin = false;
this.Swarm = false;
this.Hybrid = true;
this.ModifiedPerlin = false;
this.Dual = false;
}
if (this.BS4) {
this.Perlin = false;
this.Swarm = false;
this.Hybrid = false;
this.ModifiedPerlin = true;
this.Dual = false;
}
if (this.BS5) {
this.Perlin = false;
this.Swarm = false;
this.Hybrid = false;
this.ModifiedPerlin = false;
this.Dual = true;
}
//---below will act like a freeze, basically you will have to select a behavior type to run---
if (!this.BS) {
this.Swarm = false;
}
if (!this.BS2) {
this.Perlin = false;
}
if (!this.BS3) {
this.Hybrid = false;
}
if (!this.BS4) {
this.ModifiedPerlin = false;
}
if (!this.BS5) {
this.Dual = false;
}
for (int i = 0; i < creeperFamily.size (); i++) {
//-----initialize all the creeper fields-------
Creeper creep = (Creeper)creeperFamily.get(i);
creep.dwidth = this.BoundsWidth;
creep.ddepth = this.BoundsDepth;
creep.dheight = this.BoundsHeight;
this.rebirthType = new ArrayList<Boolean>();
this.rebirthType.add(this.SP);
this.rebirthType.add(this.SP2);
this.rebirthType.add(this.SP3);
creep.birthType = this.rebirthType;
creep.twoD = this.D2;
creep.threeD = this.D3;
creep.applyColor = this.ApplySweetColor;
creep.applyMap = this.ApplyMap;
creep.img = this.img;
creep.searchRad = this.SearchRadius;
creep.av = this.AlignValue;
creep.sv = this.SeparateValue;
creep.cv = this.CohesionValue;
creep.dual = this.Dual;
creep.currentCount = i;
if (creep.dual) {
if (i >= creeperFamily.size()/2) {
this.Swarm = false;
this.Perlin = true;
this.ModifiedPerlin = true;
} else {
this.Swarm = true;
this.Perlin = false;
this.ModifiedPerlin = false;
}
}
creep.tailChase = this.Tail_Chaser;
creep.swarm = this.Swarm;
creep.perlin = this.Perlin;
creep.modPerlin = this.ModifiedPerlin;
creep.modType_0 = this.Mod_Type_0;
creep.modType_1 = this.Mod_Type_1;
creep.modType_2 = this.Mod_Type_2;
creep.modPerlinHybrid = this.Mod_Perlin;
creep.flock_bounds = this.F_Bounds;
creep.bounceRebirth = this.Bounce_Rebirth;
creep.hybrid_bounds = this.Boundary;
creep.bounce_Spawn = this.Bounce_Spawn;
creep.bounds = this.Bounds;
creep.multiplier = this.Multiplier;
creep.scale = this.Scale;
creep.strength = this.Strength;
creep.velocity = this.Velocity;
this.Blend = this.cf.Blend.getValue();
creep.blend = this.Blend; //get the blend value between behaviors
this.MSpeed = this.cf.MSpeed.getValue();
this.MBaseSpeed = this.cf.MBaseSpeed.getValue();
creep.baseSpeed = this.MBaseSpeed;
creep.modMult = this.Mod_Mult;
creep.max = this.MSpeed;
creep.hybrid = this.Hybrid;
creep.strokeWidth = this.StrokeWidth;
creep.transparency = this.Transparency;
creep.simulate = this.simulate;
creep.trailResolution = this.TrailResolution;
creep.creeperCollection = this.creeperFamily;
if (this.ApplyMap) {
creep.mapAV = this.cf.checkFlockBox.getState(0);
creep.mapSV = this.cf.checkFlockBox.getState(1);
creep.mapCV = this.cf.checkFlockBox.getState(2);
creep.mapPS = this.cf.checkPerlinBox.getState(0);
creep.mapPSC = this.cf.checkPerlinBox.getState(1);
creep.mapPM = this.cf.checkPerlinBox.getState(2);
}
if (this.HeadWidth > 0) {
pushStyle();
stroke(255, 255, 255); //Stroke Value
strokeWeight(this.HeadWidth); //ThickLines
if (this.D2) {
point(creep.loc.x, creep.loc.y, 0);
} else if (this.D3) {
point(creep.loc.x, creep.loc.y, creep.loc.z);
}
popStyle();
}
creep.enableInfluencers = this.Enable_Influence;
this.MaxConn = this.cf.MaxConn.getValue();
creep.maxConn = this.MaxConn;
this.ConnDist = this.cf.ConnDist.getValue();
creep.connDist = this.ConnDist;
this.Max_Repulsion = this.cf.MaxRep.getValue();
creep.maxRepel = this.Max_Repulsion;
this.Max_Attraction = this.cf.MaxAtt.getValue();
creep.maxAttract = this.Max_Attraction;
this.Repulsion = this.cf.Rep.getValue();
creep.rep = this.Repulsion;
this.Attraction = this.cf.Att.getValue();
creep.att = this.Attraction;
creep.repeller = repeller;
creep.att_A = seekerTarg;
creep.att_B = seekerTargB;
creep.tailViewAngle = this.Trail_ViewAngle;
creep.tailCohMag = this.Follow_Coh_Mag;
creep.tailCohViewRange = this.Follow_Coh_Range;
creep.tailSepMag = this.Follow_Sep_Mag;
creep.tailSepViewRange = this.Follow_Sep_Range;
creep.action();
noFill();
if (this.Tail_Chaser) {
if (i!= 200000000) {
if (creep.followerTrailData.size() > 0) {
for (int rs = 0; rs < creep.followerTrailData.size (); rs++) {
List<PVector> followedVecs = creep.followerTrailData.get(rs);
ArrayList followerColors = new ArrayList();
followerColors = creep.followerColorData.get(rs);
pushStyle();
strokeWeight((Float) followerColors.get(0));
stroke((Integer) followerColors.get(1), (Float) followerColors.get(2));
line(followedVecs.get(0).x, followedVecs.get(0).y, followedVecs.get(0).z, followedVecs.get(1).x, followedVecs.get(1).y, followedVecs.get(1).z);
popStyle();
}
}
}
totTail.addAll(creep.copyTrail);
creep.getFollowers(totTail);
}
//------if you want the heads switch the renderer from FX2D to P3D
if (!this.Tail_Chaser) {
//----draw the trails----
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);
strokeWeight((Float) colors.get(0));
stroke((Integer) colors.get(1), (Float) colors.get(2));
} else {
if (creep.dual) {
if (i >= creeperFamily.size()/2) {
strokeWeight(1);
stroke(color(255, 0, 0), 255);
} else {
strokeWeight(1);
stroke(color(255, 255, 255), 255);
}
} else {
strokeWeight(0.5);
stroke(255, 255);
}
}
if (this.D2) {
line(vecs.get(0).x, vecs.get(0).y, vecs.get(1).x, vecs.get(1).y);
} else if (this.D3) {
line(vecs.get(0).x, vecs.get(0).y, vecs.get(0).z, vecs.get(1).x, vecs.get(1).y, vecs.get(1).z);
}
}
}
}
}
}
tiler.post();
totTail.clear();
if (this.D2) {
surface.setSize((int)this.BoundsWidth, (int)this.BoundsDepth);
}
if (this.Enable_Influence) {
pushStyle();
// -------------- draw repeller
float ampR = 5;
pushStyle();
for (int i = 0; i < ampR; i++) {
noFill();
strokeWeight(1);
stroke(255, 200, 200, map(i, 0, ampR, 255, 0));
ellipse(repeller.x, repeller.y, i*40, i*40);
}
popStyle();
// -------------- draw attractor
float ampA = 4;
pushStyle();
for (int i = 0; i < ampA; i++) {
noFill();
strokeWeight(1);
stroke(0, 200, 0, map(i, 0, ampA, 255, 0));
ellipse(seekerTarg.x, seekerTarg.y, i*25, i*25);
ellipse(seekerTargB.x, seekerTargB.y, i*25, i*25);
}
popStyle();
}
}
void drawExtents()
{
pushStyle();
pushMatrix();
strokeWeight(.5);
stroke(200);
noFill();
translate(this.BoundsWidth/2, this.BoundsDepth/2, this.BoundsHeight/2);
box(this.BoundsWidth, this.BoundsDepth, this.BoundsHeight);
popMatrix();
popStyle();
}
public void RESET(boolean rflag) {
if (rflag) {
this.rCount ++;
setup();
}
}
public void ShowMap(boolean flag) {
if (flag==true) {
mapVal = true;
} else {
mapVal = false;
}
}
public void keyPressed() {
simulate = !simulate;
}
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
public void keyReleased() {
tiler.init(timestamp()+".png", imageRes);
simulate = !simulate;
}