logo

prolebra_2DBabyMakingTrackers_Main

import java.util.List;
import toxi.geom.*;
import controlP5.*;
//-------------------------------------------------------------------------------------------
Tracker a;
ControlP5 cp5;
GUI cgui;
Path tempPath;

Vec3D locStart;
Vec3D triggerLoc = new Vec3D(0, 0, 0);

boolean simulate;
boolean diagram,drawFutureLoc,addNew;
boolean drawPaths = true;
boolean spawnEdge = true;
int resetAmount = 0; 
int agentCount = 100;
int triggerCount = 0;
int pathCount = 10;
float stepCount = 0;

List<Tracker> agentList;
ArrayList<Vec3D>childSpawners;
ArrayList childSpawnType;
ArrayList<Path> pathList;
//-------------------------------------------------------------------------------------------
//---------------------------------------Settings--------------------------------------------
//-------------------------------------------------------------------------------------------
void settings() {
  size(1800, 1000, FX2D);
  smooth();
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Setup-----------------------------------------------
//-------------------------------------------------------------------------------------------
void setup() {
  background(0);

  this.agentList = new ArrayList<Tracker>();
  this.childSpawners = new ArrayList<Vec3D>();
  this.childSpawnType = new ArrayList();
  this.pathList = new ArrayList<Path>();
  this.simulate = true;

  if (this.resetAmount == 0) {
    this.cgui = new GUI();
    this.cgui.run(this);
  }
  for (int pth = 0; pth < this.pathCount; pth++) {
    newPath();
  }
  for (int i = 0; i < this.agentCount; i ++) {
    Vec3D speed;
    if (this.spawnEdge) {
      this.locStart = new Vec3D(0, random(height), 0);
      speed = new Vec3D(1, 0, 0);
    } else {
      this.locStart = new Vec3D(random(width), random(height), 0);
      speed = new Vec3D(random(-1, 1), random(-1, 1), 0);
    }
    this.a = new Tracker(this.locStart, speed, true, "parent", "main");
    this.agentList.add(this.a);
  }
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Draw------------------------------------------------
//-------------------------------------------------------------------------------------------
void draw() {
  background(0);

  this.spawnEdge = this.cgui.t0.getState();
  this.agentCount = (int)this.cgui.s7.getValue();
  for (Path pths : pathList) {
    if (drawPaths) {
      pths.display();
    }
    pths.radius = this.cgui.s0.getValue();
  }

  for (Tracker ag : this.agentList) {
    ag.wanderD = this.cgui.sw1.getValue();
    ag.wanderR = this.cgui.s1.getValue();
    ag.wanderT = this.cgui.sw3.getValue();
    ag.wanderTVal = this.cgui.sw2.getValue();

    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.maxDist = this.cgui.s2.getValue();
    ag.r = this.cgui.s3.getValue();
    ag.maxChildren = (int)this.cgui.s8.getValue();
    ag.run();
  }

  if (this.childSpawners.size() > 0) {
    newDude();
    this.childSpawners = new ArrayList<Vec3D>();
    this.childSpawnType = new ArrayList();
  }
  this.stepCount++;
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Create New Path-------------------------------------
//-------------------------------------------------------------------------------------------
void newPath() {
  this.tempPath = new Path();
  this.tempPath.addPoint(random(30, 300), random(height/4, height));
  this.tempPath.addPoint(random(101, width/2), random(0, height));
  this.tempPath.addPoint(random(width/2, width), random(0, height));
  this.tempPath.addPoint(random(width-100, width), height/2);
  this.pathList.add(this.tempPath);
}
//-------------------------------------------------------------------------------------------
//---------------------------------------Keys------------------------------------------------
//-------------------------------------------------------------------------------------------
void keyPressed() {
  if (key == 'R') {
    this.resetAmount ++;
    this.triggerCount = 0;
    setup();
  }
  if (key == 'S') this.simulate = !this.simulate;
  if (key == 'W') newPath();
  if (key == 'Q') this.drawFutureLoc = !this.drawFutureLoc;
  if (key == 'Q') this.diagram = !this.diagram;
  if (key == 'P') this.drawPaths = !this.drawPaths;
  if (key == 'I') saveFrame("img-######.png");
}
//-------------------------------------------------------------------------------------------
//----------------------------------BabyMakers-----------------------------------------------
//-------------------------------------------------------------------------------------------
void newDude() {
  int babyCount = 0;
  for (Vec3D px : this.childSpawners) {
    Vec3D speed;
    if (this.spawnEdge) {
      speed = new Vec3D(1, 0, 0);
    } else {
      speed = new Vec3D(random(-1, 1), random(-1, 1), 0);
    }
    if ((int)this.childSpawnType.get(babyCount) % 2 == 0) {
      this.agentList.add(new Tracker(new Vec3D(px), speed, false, "child", "w_a"));
    } else {
      this.agentList.add(new Tracker(new Vec3D(px), speed, false, "child", "w_b"));
    }
    babyCount++;
  }
}
Update
  • Share