import java.util.List; import toxi.geom.*; import toxi.color.*; import controlP5.*; import peasy.*; Tracker a; ControlP5 cp5; Culebra_UI cgui; Path tempPath; PVector locStart; PVector triggerLoc = new PVector(0, 0, 0); boolean simulate, spawnEdge, addNew, D2; boolean drawPathTargets, toggleUI, drawMovement, mathBehavior, genRandom, triggerSeekers, toggleColor; boolean drawPaths = true; boolean SpawnEdge = true; boolean Dimension = true; boolean enablePathTrack = true; int triggerCount = 0; int agentCount = 500; int resetAmount = 0; int camToggle = 0; int pathCount = 10; float WanderRadius, WanderDist, WanderTheta, WanderRotTrigger, MaxChildren; float PathRad, ScalarProjectDist, PathThresh; float InitSpeed, MaxSpeed, MaxForce, MaxSep; float AgentCount; float seekerTrail, childSeekerTrail; float HeadWidth, StrokeWidth, Transparency; float stepCount = 0; ArrayList<PVector>childSpawners; ArrayList childSpawnType; ArrayList<Path> pathList; List<Tracker> agentList; PeasyCam cam; CameraState state; //---------------------------------------Settings-------------------------------------------- void settings() { size(1920, 1080, P3D); smooth(); } //---------------------------------------Setup----------------------------------------------- void setup() { background(0); //surface.setLocation(640, 10); this.agentList = new ArrayList<Tracker>(); this.childSpawners = new ArrayList<PVector>(); this.childSpawnType = new ArrayList(); this.pathList = new ArrayList<Path>(); if (!this.D2 && this.camToggle < 1) { this.camToggle ++; this.cam = new PeasyCam(this, 1500); this.cam.setMinimumDistance(100); this.cam.setMaximumDistance(10000); this.cam.lookAt(1200/2, 800/2, 1000/2); this.cam.setSuppressRollRotationMode(); } if (D2) { this.cam.reset(); this.cam.setMinimumDistance(100); this.cam.setMaximumDistance(10000); this.cam.lookAt(1920/2, 1080/2, 0); this.cam.setDistance(1080); // distance from looked-at point this.cam.setSuppressRollRotationMode(); } simulate = true; if (this.resetAmount == 0) { this.cgui = new Culebra_UI(); this.cgui.run(this); } for (int pth = 0; pth < this.pathCount; pth++) { newPath(); } for (int i = 0; i < this.agentCount; i ++) { PVector speed; if (this.D2) { if (this.spawnEdge) { locStart = new PVector(0, random(height), 0); speed = new PVector(1, 0, 0); } else { locStart = new PVector(random(width), random(height), 0); speed = new PVector(random(-1, 1), random(-1, 1), 0); } this.a = new Tracker(locStart, speed, true, "parent", "main"); } else { if (this.spawnEdge) { locStart = new PVector(random(width), random(height), 0); speed = new PVector(random(-1, 1), random(-1, 1), random(0, 2)); } else { locStart = new PVector(random(width), random(height), random(0, 1000)); speed = new PVector(random(-1, 1), random(-1, 1), random(-1, 1)); } this.a = new Tracker(locStart, speed, true, "parent", "main"); } this.agentList.add(this.a); } } //---------------------------------------Draw------------------------------------------------ void draw() { background(0); this.D2 = this.cgui.d.getState(); if (!this.D2) { drawExtents(); } this.spawnEdge = this.cgui.se.getState(); this.agentCount = (int)this.cgui.ac.getValue(); for (Path pths : pathList) { if (this.drawPaths) { pths.display(); } pths.dim = this.cgui.d.getState(); pths.radius = this.cgui.pr.getValue(); } for (Tracker ag : agentList) { if (ag.type == "parent") { ag.wanderD = this.cgui.wd.getValue(); ag.wanderR = this.cgui.wr.getValue(); ag.wanderT = this.cgui.wt.getValue(); ag.wanderTVal = this.cgui.wrt.getValue(); ag.headWidth = this.cgui.hw.getValue(); ag.strokeWidth = this.cgui.stw.getValue(); ag.tranparency = this.cgui.t.getValue(); ag.seekerMT = (int)this.cgui.st.getValue(); ag.maxforce = this.cgui.mf.getValue(); ag.max = this.cgui.ms.getValue(); ag.amp = this.cgui.sd.getValue(); ag.vel = this.cgui.is.getValue(); ag.maxDist = this.cgui.pt.getValue(); ag.r = this.cgui.msep.getValue(); ag.maxChildren = (int)this.cgui.mc.getValue(); ag.dim = this.cgui.d.getState(); ag.randomize = this.genRandom; ag.wandertheta = 0.0f; ag.run(); } else { ag.wanderD = this.cgui.c_wd.getValue(); ag.wanderR = this.cgui.c_wr.getValue(); ag.wanderT = this.cgui.c_wt.getValue(); ag.wanderTVal = this.cgui.c_wrt.getValue(); ag.headWidth = this.cgui.c_hw.getValue(); ag.strokeWidth = this.cgui.c_stw.getValue(); ag.tranparency = this.cgui.c_t.getValue(); ag.seekerChildMT = (int)this.cgui.c_ct.getValue(); ag.maxforce = this.cgui.c_mf.getValue(); ag.max = this.cgui.c_ms.getValue(); ag.amp = this.cgui.c_sd.getValue(); ag.vel = this.cgui.c_is.getValue(); ag.maxDist = this.cgui.c_pt.getValue(); //ag.r = this.cgui.c_msep.getValue(); ag.maxChildren = 0; ag.dim = this.cgui.d.getState(); ag.randomize = this.genRandom; ag.wandertheta = 0.0f; ag.run(); } } if (this.childSpawners.size() > 0) { newDude(); this.childSpawners = new ArrayList<PVector>(); this.childSpawnType = new ArrayList(); } stepCount++; if (this.D2) { surface.setSize(1920, 1080); } this.cgui.createGui(); } //---------------------------------------Create Static Paths--------------------------------- void newPath() { if (this.D2) { this.tempPath = new Path(); this.tempPath.addPoint(random(30, 300), random(height/4, height), 0); this.tempPath.addPoint(random(101, width/2), random(0, height), 0); this.tempPath.addPoint(random(width/2, width), random(0, height), 0); this.tempPath.addPoint(random(width-100, width), height/2, 0); } else { this.tempPath = new Path(); this.tempPath.addPoint(random(30, 300), random(height/4, height), random(1000/8, 1000)); this.tempPath.addPoint(random(101, width/2), random(0, height), random(1000/4, 1000)); this.tempPath.addPoint(random(width/2, width), random(0, height), random(1000/10, 1000)); this.tempPath.addPoint(random(width-100, width), height/2, random(1000/3, 1000)); } this.pathList.add(this.tempPath); } //---------------------------------------Keyboard Inputs------------------------------------- void keyPressed() { if (key == 'r') { this.resetAmount ++; this.triggerCount = 0; setup(); } if (key == 's') this.simulate = !this.simulate; if (key == 'w') this.newPath(); if (key == 'q') this.drawPathTargets = !this.drawPathTargets; if (key == 'p') this.drawPaths = !this.drawPaths; if (key == 't') this.toggleUI = !this.toggleUI; if (key == 'm') this.mathBehavior = !this.mathBehavior; if (key == 'n') this.genRandom = !this.genRandom; if (key == 'd') this.drawMovement = !this.drawMovement; if (key == 'P') this.enablePathTrack = !this.enablePathTrack; if (key == 'b') this.triggerSeekers = !this.triggerSeekers; if (key == 'c') this.toggleColor = !this.toggleColor; if (key == 'i') saveFrame("img-######.png"); } //---------------------------------------Children Creation----------------------------------- void newDude() { int babyCount = 0; for (PVector px : this.childSpawners) { PVector speed; if (this.spawnEdge) { speed = new PVector(1, 0, 0); } else { speed = new PVector(random(-1, 1), random(-1, 1), 0); } if ((int)this.childSpawnType.get(babyCount) % 2 == 0) { this.agentList.add(new Tracker(new PVector(px.x, px.y, px.z), speed, false, "child", "w_a")); } else { this.agentList.add(new Tracker(new PVector(px.x, px.y, px.z), speed, false, "child", "w_b")); } babyCount++; } } //---------------------------------------Draw Bounds----------------------------------------- void drawExtents() { pushStyle(); pushMatrix(); strokeWeight(.5); stroke(200); noFill(); translate(1980/2, 1080/2, 1000/2); box(1980, 1080, 1000); popMatrix(); popStyle(); } Update