logo

[P]rolebra.0.9B2

Projects details

Download the App – prolebra0.9B2

prolebra processing behavior library beta2 tests

 

MAINAPP
MAIN - With Imported Beta Behavior Library
//--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;
}
TILER
// TileSaver.pde - v0.12 2007.0326
// Marius Watz - http://workshop.evolutionzone.com
//
// Class for rendering high-resolution images by splitting them into
// tiles using the viewport.
class TileSaver {
  public boolean isTiling=false,done=true;
  public boolean doSavePreview=false;
  PApplet p;
  float FOV=60; // initial field of view
  float cameraZ, width, height;
  int tileNum=10,tileNumSq; // number of tiles
  int tileImgCnt, tileX, tileY, tilePad;
  boolean firstFrame=false, secondFrame=false;
  String tileFilename,tileFileextension=".png";
  PImage tileImg;
  float perc,percMilestone;
  // The constructor takes a PApplet reference to your sketch.
  public TileSaver(PApplet _p) {
    p=_p;
  }
  // If init() is called without specifying number of tiles, getMaxTiles()
  // will be called to estimate number of tiles according to free memory.
  public void init(String _filename) {
    init(_filename,getMaxTiles(p.width));
  }
  // Initialize using a filename to output to and number of tiles to use.
  public void init(String _filename,int _num) {
    tileFilename=_filename;
    tileNum=_num;
    tileNumSq=(tileNum*tileNum);
    width=p.width;
    height=p.height;
    cameraZ=(height/2.0f)/p.tan(p.PI*FOV/360.0f);
    p.println("TileSaver: "+tileNum+" tilesnResolution: "+
      (p.width*tileNum)+"x"+(p.height*tileNum));
    // remove extension from filename
    if(!new java.io.File(tileFilename).isAbsolute())
      tileFilename=p.sketchPath(tileFilename);
    tileFilename=noExt(tileFilename);
    p.createPath(tileFilename);
    // save preview
    if(doSavePreview) p.g.save(tileFilename+"_preview.png");
    // set up off-screen buffer for saving tiled images
    tileImg=new PImage(p.width*tileNum, p.height*tileNum);
    // start tiling
    done=false;
    isTiling=false;
    perc=0;
    percMilestone=0;
    tileInc();
  }
  // set filetype, default is TGA. pass a valid image extension as parameter.
  public void setSaveType(String extension) {
    tileFileextension=extension;
    if(tileFileextension.indexOf(".")==-1) tileFileextension="."+tileFileextension;
  }
  // pre() handles initialization of each frame.
  // It should be called in draw() before any drawing occurs.
  public void pre() {
    if(!isTiling) return;
    if(firstFrame) firstFrame=false;
    else if(secondFrame) {
      secondFrame=false;
    }
    setupCamera();
  }
  // post() handles tile update and image saving.
  // It should be called at the very end of draw(), after any drawing.
  public void post() {
    // If first or second frame, don't update or save.
    if(firstFrame||secondFrame|| (!isTiling)) return;
    // Find image ID from reverse row order
    int imgid=tileImgCnt%tileNum+(tileNum-tileImgCnt/tileNum-1)*tileNum;
    int idx=(imgid+0)%tileNum;
    int idy=(imgid/tileNum);
    // Get current image from sketch and draw it into buffer
    p.loadPixels();
    tileImg.set(idx*p.width, idy*p.height, p.g);
    // Increment tile index
    tileImgCnt++;
    perc=100*((float)tileImgCnt/(float)tileNumSq);
    if(perc-percMilestone>5 || perc>99) {
      p.println(p.nf(perc,3,2)+"% completed. "+tileImgCnt+"/"+tileNumSq+" images saved.");
      percMilestone=perc;
    }
    if(tileImgCnt==tileNumSq) tileFinish();
    else tileInc();
  }
  public boolean checkStatus() {
    return isTiling;
  }
  // tileFinish() handles saving of the tiled image
  public void tileFinish() {
    isTiling=false;
    restoreCamera();
    // save large image to TGA
    tileFilename+="_"+(p.width*tileNum)+"x"+
      (p.height*tileNum)+tileFileextension;
    p.println("Save: "+
      tileFilename.substring(
    tileFilename.lastIndexOf(java.io.File.separator)+1));
    tileImg.save(tileFilename);
    p.println("Done tiling.n");
    // clear buffer for garbage collection
    tileImg=null;
    done=true;
  }
  // Increment tile coordinates
  public void tileInc() {
    if(!isTiling) {
      isTiling=true;
      firstFrame=true;
      secondFrame=true;
      tileImgCnt=0;
    } 
    else {
      if(tileX==tileNum-1) {
        tileX=0;
        tileY=(tileY+1)%tileNum;
      } 
      else
        tileX++;
    }
  }
  // set up camera correctly for the current tile
  public void setupCamera() {
    p.camera(width/2.0f, height/2.0f, cameraZ,
    width/2.0f, height/2.0f, 0, 0, 1, 0);
    if(isTiling) {
      float mod=1f/10f;
      p.frustum(width*((float)tileX/(float)tileNum-.5f)*mod,
      width*((tileX+1)/(float)tileNum-.5f)*mod,
      height*((float)tileY/(float)tileNum-.5f)*mod,
      height*((tileY+1)/(float)tileNum-.5f)*mod,
      cameraZ*mod, 10000);
    }
  }
  // restore camera once tiling is done
  public void restoreCamera() {
    float mod=1f/10f;
    p.camera(width/2.0f, height/2.0f, cameraZ,
    width/2.0f, height/2.0f, 0, 0, 1, 0);
    p.frustum(-(width/2)*mod, (width/2)*mod,
    -(height/2)*mod, (height/2)*mod,
    cameraZ*mod, 10000);
  }
  // checks free memory and gives a suggestion for maximum tile
  // resolution. It should work well in most cases, I've been able
  // to generate 20k x 20k pixel images with 1.5 GB RAM allocated.
  public int getMaxTiles(int width) {
    // get an instance of java.lang.Runtime, force garbage collection
    java.lang.Runtime runtime=java.lang.Runtime.getRuntime();
    runtime.gc();
    // calculate free memory for ARGB (4 byte) data, giving some slack
    // to out of memory crashes.
    int num=(int)(Math.sqrt(
    (float)(runtime.freeMemory()/4)*0.925f))/width;
    p.println(((float)runtime.freeMemory()/(1024*1024))+"/"+
      ((float)runtime.totalMemory()/(1024*1024)));
    // warn if low memory
    if(num==1) {
      p.println("Memory is low. Consider increasing memory settings.");
      num=2;
    }
    return num;
  }
  // strip extension from filename
  String noExt(String name) {
    int last=name.lastIndexOf(".");
    if(last>0)
      return name.substring(0, last);
    return name;
  }
}
Update
JAVA CREEPER PACKAGE
JAVA CREEPER CLASS
package creeper_Behavior_P3_2_3D_SET3;
import processing.core.*;
import java.util.ArrayList;
import java.util.List;
import toxi.color.*;
import java.util.Random;
import creeper_Behavior_P3_2_3D_SET3.ImprovedPerlinNoise;
public class Creeper {
    // Location
    public PVector loc;
    // Speed
    private PVector chaser_speed;
    public PVector speed;
    // Acceleration
    private PVector acc = new PVector();
    // Agent Trails
    public ArrayList<PVector> creeperTrails;
    public List<Creeper> creeperCollection;
    public List<List<PVector>> trailData;
    public List<List<PVector>> followerTrailData = new ArrayList<List<PVector>>();
    public List<ArrayList> followerColorData = new ArrayList<ArrayList>();
    public List<ArrayList> trailColors;
    public List<Boolean> birthType;
    public List<PVector> pvecList;
    public List<PVector> copyTrail = new ArrayList<PVector>();;
    public float dwidth, ddepth, dheight;
    public float searchRad, av, sv, cv;
    public float connThresh, connect, max, baseSpeed, modMult;
    public boolean swarm, perlin, hybrid, bounds, needsRefresh, applyMap, applyColor, modPerlin, dual, modPerlinHybrid,
            modType_0, modType_1, modType_2, modType_3, tailChase, enableInfluencers;
    public boolean twoD, threeD, flock_bounds, bounceRebirth, hybrid_bounds, bounce_Spawn;
    // ----------------Tail Chaser Variables---------------------
    public float tailViewAngle, tailCohMag, tailCohViewRange, tailSepMag, tailSepViewRange;
    private PVector tailPerip = new PVector();
    private float tailAngle, tailVAngle;
    private PVector FutVec;
    private PVector FutLocation;
    private float futLocMag = 10.0f;
    public int Tcount = 0;
    public float maxConn, connDist;
    public int TStep = 6;
    public float maxRepel, maxAttract, rep, att;
    public PVector repeller, att_A, att_B;
    // ----------------------------------------------------------
    public PImage img;
    private List<PVector> otherPtsList;
    private List<PVector> otherMoveValues;
    private List<Float> allDist;
    private PVector cummVec, alignVector, separateVector, cohesionVector;
    private TColor colorA = TColor.newRGB(255.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f); 
    private TColor colorB = TColor.newRGB(120.0f, 0.0f, 0.0f);
    private TColor colorB2 = TColor.newRGB(0.0f, 255.0f, 255.0f);
    private TColor colorC = TColor.newRGB(187.0f / 255.0f, 216.0f / 255.0f, 40.0f / 255.0f);
    private ColorGradient gradA = new ColorGradient();
    private ColorGradient gradB = new ColorGradient();
    private ToneMap toneMapA, toneMapB;
    public boolean simulate;
    public float strokeWidth, transparency;
    public int trailResolution, currentCount;
    private float newMap;
    public boolean mapAV, mapSV, mapCV, mapPS, mapPSC, mapPM;
    // -----Noise Fields-------
    public float multiplier, scale, strength, velocity, blend;
    private Random r;
    // CONSTRUCTOR - INITIALIZE THE CLASS
    // -------------------------------------------------------------------------------------
    public Creeper(PVector origin, PVector speed, float dwidth, float ddepth) {
        this.loc = origin;
        this.creeperTrails = new ArrayList<PVector>();
        this.speed = speed;
        this.dwidth = dwidth;
        this.ddepth = ddepth;
        this.creeperCollection = new ArrayList<Creeper>();
        chaser_speed = speed;
        gradA.addColorAt(0.0f, colorA);
        gradA.addColorAt(255.0f, colorC);
        toneMapA = new ToneMap(0.0f, 1.0f, gradA);
        gradB.addColorAt(0.0f, colorB);
        gradB.addColorAt(255.0f, colorB2);
        toneMapB = new ToneMap(0.0f, 1.0f, gradB);
    }
    // CONSTRUCTOR - INITIALIZE THE CLASS
    // -------------------------------------------------------------------------------------
    public Creeper(PVector origin, PVector speed, float dwidth, float ddepth, int dheight) {
        this.loc = origin;
        this.creeperTrails = new ArrayList<PVector>();
        this.speed = speed;
        this.dwidth = dwidth;
        this.dheight = dheight;
        this.ddepth = ddepth;
        this.creeperCollection = new ArrayList<Creeper>();
        chaser_speed = speed;
        gradA.addColorAt(0.0f, colorA);
        gradA.addColorAt(255.0f, colorC);
        toneMapA = new ToneMap(0.0f, 1.0f, gradA);
        gradB.addColorAt(0.0f, colorB);
        gradB.addColorAt(255.0f, colorB2);
        toneMapB = new ToneMap(0.0f, 1.0f, gradB);
    }
    // ALL FUNCTIONS
    // ---------------------------------------------------------------------------------------------------------
    public void action() {
        this.r = new Random();
        if (this.simulate) {
            if (this.swarm) {
                if (this.tailChase) {
                    chaser_speed.limit(this.max);
                    this.loc.add(this.chaser_speed);
                    acc = new PVector();
                    if (this.flock_bounds) {
                        if (this.bounceRebirth) {
                            chaser_bounce();
                        } else {
                            checkLoc();
                        }
                    }
                    drawChasedTrails();
                    FutLoc();
                    getAngle();
                    if (this.enableInfluencers) {
                        seek(att_A);
                        seek(att_B);
                        repel(repeller);
                    }
                } else {
                    flocking();
                    if (this.flock_bounds) {
                        if (this.bounceRebirth) {
                            bounce();
                        } else {
                            checkLoc();
                        }
                    }
                    this.loc.add(speed);
                    if (this.twoD) {
                        this.creeperTrails.add(new PVector(loc.x, loc.y, 0));
                    } else if (this.threeD) {
                        this.creeperTrails.add(new PVector(loc.x, loc.y, loc.z));
                    }
                }
            }
            if (this.perlin || this.modPerlin) {
                if (this.modPerlin) {
                    if (this.modType_0) {
                        this.scale = GetRandomNumbers(this.scale, this.scale * this.modMult / 2, this.r);
                    }
                    if (this.modType_1) {
                        this.scale = GetRandomNumbers(-this.scale, this.scale * this.modMult, this.r);
                    }
                    if (this.modType_2) {
                        this.strength = GetRandomNumbers(this.strength, this.strength * this.modMult, this.r);
                    }
                }
                perlinNoise();
                if (this.bounds) {
                    checkLoc();
                }
                speed = new PVector();
                speed.add(acc);
                this.loc.add(speed);
                this.creeperTrails.add(new PVector(loc.x, loc.y, loc.z));
                acc = new PVector();
            }
            if (this.hybrid) {
                if (this.modPerlinHybrid) {
                    if (this.modType_0) {
                        this.scale = GetRandomNumbers(this.scale, this.scale * this.modMult / 2, this.r);
                    }
                    if (this.modType_1) {
                        this.scale = GetRandomNumbers(-this.scale, this.scale * this.modMult, this.r);
                    }
                    if (this.modType_2) {
                        this.strength = GetRandomNumbers(this.strength, this.strength * this.modMult, this.r);
                    }
                }
                perlinNoise();
                flocking();
                if (this.hybrid_bounds) {
                    if (bounce_Spawn) {
                        bounce();
                    } else {
                        checkLoc();
                    }
                }
                speed.add(acc);
                speed.limit(this.max);
                this.loc.add(speed);
                this.creeperTrails.add(new PVector(loc.x, loc.y, loc.z));
                acc = new PVector();
            }
            if (!this.swarm && !this.perlin && !this.hybrid) {
                this.acc = new PVector(1.0f, 0, 0);
            }
            trails();
        }
    }
    private void checkLoc() {
        if (this.twoD) {
            if (loc.x > dwidth || this.loc.x < 0 || this.loc.y > ddepth || this.loc.y < 0) {
                this.needsRefresh = true;
                float x = GetRandomNumbers(0.0f, dwidth, this.r);
                float y = GetRandomNumbers(0.0f, ddepth, this.r);
                this.loc = new PVector(x, y, 0);
                this.creeperTrails = new ArrayList<PVector>();
            }
        } else if (this.threeD) {
            if (loc.x > dwidth || this.loc.x < 0 || this.loc.y > ddepth || this.loc.y < 0 || this.loc.z > dheight
                    || this.loc.z < 0) {
                this.needsRefresh = true;
                if (this.birthType.get(1)) {
                    float x = GetRandomNumbers(0.0f, dwidth, this.r);
                    float y = GetRandomNumbers(0.0f, ddepth, this.r);
                    float z = GetRandomNumbers(0.0f, dheight, this.r);

                    this.loc = new PVector(x, y, z);
                } else if (this.birthType.get(2)) {
                    float x = GetRandomNumbers(0.0f, dwidth, this.r);
                    float y = GetRandomNumbers(0.0f, ddepth, this.r);
                    this.loc = new PVector(x, y, 0);
                }
                this.creeperTrails = new ArrayList<PVector>();
            }
        }
    }
    private void chaser_bounce() {
        if (this.twoD) {
            if (loc.x > dwidth) {
                this.chaser_speed.x = this.chaser_speed.x * -1;
            }
            if (loc.x < 0) {
                this.chaser_speed.x = this.chaser_speed.x * -1;
            }
            if (loc.y > ddepth) {
                this.chaser_speed.y = this.chaser_speed.y * -1;
            }
            if (loc.y < 0) {
                this.chaser_speed.y = this.chaser_speed.y * -1;
            }
        } else if (this.threeD) {
            if (loc.x > dwidth) {
                this.chaser_speed.x = this.chaser_speed.x * -1;
            }
            if (loc.x < 0) {
                this.chaser_speed.x = this.chaser_speed.x * -1;
            }
            if (loc.y > ddepth) {
                this.chaser_speed.y = this.chaser_speed.y * -1;
            }
            if (loc.y < 0) {
                this.chaser_speed.y = this.chaser_speed.y * -1;
            }
            if (loc.z > dheight) {
                this.chaser_speed.z = this.chaser_speed.z * -1;
            }
            if (loc.z < 0) {
                this.chaser_speed.z = this.chaser_speed.z * -1;
            }
        }
    }
    // BOUNCE METHOD
    // ------------------------------------------------------------------------------------------------------------
    private void bounce() {
        if (this.twoD) {
            if (loc.x > dwidth) {
                speed.x = speed.x * -1;
            }
            if (loc.x < 0) {
                speed.x = speed.x * -1;
            }
            if (loc.y > ddepth) {
                speed.y = speed.y * -1;
            }
            if (loc.y < 0) {
                speed.y = speed.y * -1;
            }
        } else if (this.threeD) {
            if (loc.x > dwidth) {
                speed.x = speed.x * -1;
            }
            if (loc.x < 0) {
                speed.x = speed.x * -1;
            }
            if (loc.y > ddepth) {
                speed.y = speed.y * -1;
            }
            if (loc.y < 0) {
                speed.y = speed.y * -1;
            }
            if (loc.z > dheight) {
                speed.z = speed.z * -1;
            }
            if (loc.z < 0) {
                speed.z = speed.z * -1;
            }
        }
    }
    private float GetRandomNumbers(double minimum, double maximum, Random r) {
        double rX = this.r.nextDouble() * (maximum - minimum) + minimum;
        float fX = (float) rX;
        return fX;
    }
    private PVector GetRandomNumber(double minimum, double maximum, Random r) {
        PVector rando = new PVector();
        double rX = this.r.nextDouble() * (maximum - minimum) + minimum;
        double rY = this.r.nextDouble() * (maximum - minimum) + minimum;
        double rZ = this.r.nextDouble() * (maximum - minimum) + minimum;
        float fX = (float) rX;
        float fY = (float) rY;
        float fZ = (float) rZ;
        rando.x = fX;
        rando.y = fY;
        if (this.threeD) {
            rando.z = fZ;
        } else {
            rando.z = 0.0f;
        }
        return rando;
    }
    private void perlinNoise() {
        if (!this.applyMap) {
            PVector multSpeed = GetRandomNumber(-this.multiplier, this.multiplier, this.r);
            double noiseVal = 1.0;
            double noiseValZ = 1.0;
            float offset = 0;
            float stepOver = 1;
            if (this.twoD) {
                noiseVal = ImprovedPerlinNoise.noise(this.loc.x / (Float) this.scale, this.loc.y / (Float) this.scale,
                        0.0) * this.strength;
            } else if (this.threeD) {
                noiseVal = ImprovedPerlinNoise.noise(this.loc.x / (Float) this.scale, this.loc.y / (Float) this.scale,
                        this.loc.z / (Float) this.scale) * this.strength;
                noiseValZ = ImprovedPerlinNoise.noise(this.loc.x / (Float) this.scale + offset,
                        this.loc.y / (Float) this.scale, this.loc.z / (Float) this.scale) * this.strength;
            }
            double angle = noiseVal;
            double angleZ = noiseValZ; 
            PVector dir = new PVector();
            if (this.twoD) {
                double ddX = Math.cos(angle);
                float dX = (float) ddX;
                double ddY = Math.sin(angle);
                float dY = (float) ddY;
                dir = new PVector(dX, dY, 0);
            }
            if (this.threeD) {
                double ddX = Math.cos(angleZ) * Math.cos(angle) * stepOver;
                float dX = (float) ddX;
                double ddY = Math.sin(angleZ);
                float dY = (float) ddY;
                double ddZ = Math.cos(angleZ) * Math.sin(angle) * stepOver;
                float dZ = (float) ddZ;
                dir = new PVector(dX, dY, dZ);
            }
            if (this.hybrid) {
                dir.mult(this.baseSpeed);
            } else {
                dir.mult(this.velocity);
            }
            dir.add(multSpeed);
            this.acc.add(dir); 
        } else {
            if (this.loc.x <= img.width && this.loc.x >= 0 && this.loc.y >= 0 && this.loc.y <= img.height) {
                getColorValue();
            } else {
                this.newMap = 0;
            }
            PVector multSpeed;
            if (this.mapPM) {
                multSpeed = GetRandomNumber(-this.multiplier * this.newMap, this.multiplier * this.newMap, this.r);
            } else {
                multSpeed = GetRandomNumber(-this.multiplier, this.multiplier, this.r);
            }
            if (this.mapPSC) {
                if (this.newMap == 0.0f) {
                    this.newMap = 0.1f;
                }
                this.scale *= this.newMap;
            }
            if (this.mapPS) {
                this.strength *= this.newMap;
            }
            if (this.mapPS && this.mapPSC) {
                this.scale *= this.newMap;
                this.strength *= this.newMap;
            }
            double noiseVal = ImprovedPerlinNoise.noise(this.loc.x / (Float) this.scale,
                    this.loc.y / (Float) this.scale, 0.0f) * (this.strength);
            double angle = noiseVal;
            double ddX = Math.cos(angle);
            float dX = (float) ddX;
            double ddY = Math.sin(angle);
            float dY = (float) ddY;
            PVector dir = new PVector(dX, dY, 0);
            if (this.hybrid) {
                dir.mult(this.baseSpeed);
            } else {
                dir.mult(this.velocity);
            }
            dir.add(multSpeed);
            this.acc.add(dir);
        }
    }
    private void getColorValue() {
        double f = Math.floor(this.loc.y) * img.width + Math.floor(this.loc.x);
        Integer i = (int) f;
        Integer col = img.pixels[i];
        float red = col >> 16 & 0xFF; // Very fast to calculate
        float green = col >> 8 & 0xFF; // Very fast to calculate
        float blue = col & 0xFF; // Very fast to calculate
        int greyscale = (int) Math.round(red * 0.222 + green * 0.707 + blue * 0.071);
        newMap = map(greyscale, 0, 255, 0, 1);
    }
    public void getFollowers(List<PVector> field) {
        this.otherPtsList = new ArrayList<PVector>();
        this.otherMoveValues = new ArrayList<PVector>();
        this.allDist = new ArrayList<Float>();
        for (int i = 0; i < field.size(); i++) {
            PVector other = field.get(i);
            float distance = this.loc.dist(other);
            if (distance > 0 && distance < tailCohViewRange) {
                tailPerip = PVector.sub(field.get(i), loc);
                tailAngle = PVector.angleBetween(tailPerip, this.chaser_speed);
                if (tailAngle < 0) {
                    tailAngle += (Math.PI * 2);
                }
                if (Math.abs(tailAngle) < tailVAngle) {
                    this.otherPtsList.add(other);
                    this.allDist.add(distance);
                }
            }
        }
        if (this.otherPtsList.size() > 0) {
            this.cummVec = new PVector();
            // ----------Separate-----------------
            trailSeparate();
            if (this.separateVector.mag() > 0) {
                this.separateVector.normalize();
            }
            this.separateVector.mult(tailSepMag);
            // ----------Cohesion-----------------
            trailCohesion();
            if (this.cohesionVector.mag() > 0) {
                this.cohesionVector.normalize();
            }
            this.cohesionVector.mult(tailCohMag);
            // -----------------------------------
            this.cummVec.add(this.separateVector);
            this.cummVec.add(this.cohesionVector);

            this.chaser_speed.add(this.cummVec);
            this.chaser_speed.normalize();
            this.chaser_speed.mult(this.velocity);
        }
    }
    private void trailCohesion() {
        this.cohesionVector = new PVector();
        for (int i = 0; i < this.otherPtsList.size(); i++) {
            this.cohesionVector.add(this.otherPtsList.get(i));
        }
        PVector scaleVec = PVector.mult(this.cohesionVector, (1.00f / this.otherPtsList.size()));
        float dist = this.loc.dist(scaleVec);
        this.cohesionVector = PVector.mult(PVector.sub(scaleVec, this.loc), tailCohViewRange / dist);
    }
    // -----------Method Computes the separation----------------------------
    private void trailSeparate() {
        this.separateVector = new PVector();
        for (int i = 0; i < this.otherPtsList.size(); i++) {
            this.separateVector.add(PVector.mult(PVector.sub(this.loc, this.otherPtsList.get(i)),
                    tailSepViewRange / this.allDist.get(i)));
        }
    }
    // FLOCK METHOD
    // ---------------------------------------------------------------------------------------------------------------
    private void flocking() {
        if (this.applyMap) {
            if (this.loc.x <= img.width && this.loc.x >= 0 && this.loc.y >= 0 && this.loc.y <= img.height) {
                getColorValue();
                if (this.mapAV) {
                    this.av *= this.newMap;
                }
                if (this.mapSV) {
                    this.sv *= this.newMap;
                }
                if (this.mapCV) {
                    this.cv *= this.newMap;
                }
            } else {
                this.newMap = 0;
            }
        }
        this.otherPtsList = new ArrayList<PVector>();
        this.otherMoveValues = new ArrayList<PVector>();
        this.allDist = new ArrayList<Float>();
        for (int i = 0; i < this.creeperCollection.size(); i++) {
            Creeper other = (Creeper) creeperCollection.get(i);
            float distance = this.loc.dist(other.loc);
            if (distance > 0 && distance < this.searchRad) {
                this.otherPtsList.add(this.creeperCollection.get(i).loc);
                this.allDist.add(distance);
                this.otherMoveValues.add(this.creeperCollection.get(i).speed);
            }
        }
        if (this.otherPtsList.size() > 0) {
            this.cummVec = new PVector();
            // ----------Align-----------------
            align();
            if (this.alignVector.mag() > 0) {
                this.alignVector.normalize();
            }
            this.alignVector.mult(this.av);
            // ----------Separate-----------------
            separate();
            if (this.separateVector.mag() > 0) {
                this.separateVector.normalize();
            }
            this.separateVector.mult(this.sv);
            // ----------Cohesion-----------------
            cohesion();
            if (this.cohesionVector.mag() > 0) {
                this.cohesionVector.normalize();
            }
            this.cohesionVector.mult(this.cv);
            // -----------------------------------
            this.cummVec.add(this.alignVector);
            this.cummVec.add(this.separateVector);
            this.cummVec.add(this.cohesionVector);
            if (this.hybrid) {
                if (this.blend != 0.0 && this.blend != 1.0) {
                    acc.add(this.cummVec);
                    float newVal = 1.0f - this.blend;
                    this.acc.mult(newVal);
                } else if (this.blend == 1.0) {
                    this.acc = new PVector();
                    this.speed.add(this.cummVec);
                    this.speed.normalize();
                    this.speed.mult(this.baseSpeed);
                }
            } else {
                this.speed.add(this.cummVec);
                this.speed.normalize();
                this.speed.mult(this.velocity);
            }
        }
    }
    // COHESION
    // ---------------------------------------------------------------------------------------------------------------------
    // -----------Method Computes the cohesion-----------------------------
    private void cohesion() {
        this.cohesionVector = new PVector();
        for (int i = 0; i < this.otherPtsList.size(); i++) {
            this.cohesionVector.add(this.otherPtsList.get(i));
        }
        PVector scaleVec = PVector.mult(this.cohesionVector, (1.00f / this.otherPtsList.size()));
        float dist = this.loc.dist(scaleVec);
        this.cohesionVector = PVector.mult(PVector.sub(scaleVec, this.loc), this.searchRad / dist);
    }
    // -----------Method Computes the separation----------------------------
    private void separate() {
        this.separateVector = new PVector();
        for (int i = 0; i < this.otherPtsList.size(); i++) {
            this.separateVector.add(PVector.mult(PVector.sub(this.loc, this.otherPtsList.get(i)),
                    this.searchRad / this.allDist.get(i)));
        }
    }
    // -----------Method Computes the alignment----------------------------
    private void align() {
        this.alignVector = new PVector();
        for (int i = 0; i < this.otherPtsList.size(); i++) {
            this.alignVector.add(PVector.mult(this.otherMoveValues.get(i), this.searchRad / this.allDist.get(i)));
        }
    }
    // --------------------------------------------------------PREDICT FUT LOC
    private void FutLoc() {
        FutVec = this.chaser_speed.copy();
        FutVec.normalize();
        FutVec.mult(futLocMag);
        this.FutLocation = FutVec.add(loc);
    }
    private void drawChasedTrails() {
        followerTrailData = new ArrayList<List<PVector>>();
        followerColorData = new ArrayList<ArrayList>();
        Tcount++;
        if (Tcount > TStep) {
            this.copyTrail.add(loc.copy());
            Tcount = 0;
        }
        if (this.copyTrail.size() > maxConn) {
            this.copyTrail.remove(0);
        }
        int counter = 0;
        for (int i = 1; i < copyTrail.size(); i++) {
            List<PVector> followerVecList = new ArrayList<PVector>();
            ArrayList followerColList = new ArrayList();
            PVector a = copyTrail.get(i - 1);
            PVector b = copyTrail.get(i);
            if (a.dist(b) < connDist) {
                followerVecList.add(a);
                followerVecList.add(b);
                int c = toneMapA.getARGBToneFor(i / (1.0f * copyTrail.size()));
                float d = map(i, 0.0f, copyTrail.size(), 0.5f, this.strokeWidth);
                float e = map(i, 0.0f, copyTrail.size(), 0.0f, this.transparency);
                followerColList.add(d);
                followerColList.add(c);
                followerColList.add(e);

                followerTrailData.add(counter, followerVecList);
                followerColorData.add(counter, followerColList);
                counter++;
            }
        }
    }
    public void seek(PVector target) {
        float distanceT = target.dist(loc);
        if (distanceT > 0 && distanceT < 500) {
            PVector desired = PVector.sub(target, loc);
            desired.normalize();
            desired.mult(att);
            PVector steerTarget = PVector.sub(desired, chaser_speed);
            steerTarget.setMag(maxAttract);
            chaser_speed.add(steerTarget);
        }
    }
    // -----------------------------------REPEL TARGET
    public void repel(PVector target) {
        float distanceT = target.dist(loc);
        if (distanceT > 0 && distanceT < 150) {
            PVector desired = PVector.sub(target, loc);
            desired.normalize();
            desired.mult(rep);
            PVector steerTarget = PVector.sub(desired, chaser_speed);
            steerTarget.limit(maxRepel);
            steerTarget.mult(-1);
            chaser_speed.add(steerTarget);
        }
    }
    private void getAngle() {
        double conv = Math.toRadians(tailViewAngle);
        float angl = (float) conv;
        tailVAngle = angl;
    }
    // TRAIL METHOD
    // ---------------------------------------------------------------------------------------------------------------------------------
    private void trails() {
        this.trailData = new ArrayList<List<PVector>>();
        this.trailColors = new ArrayList<ArrayList>();
        int counter = 0;
        this.pvecList = new ArrayList<PVector>();
        for (int k = 0; k < creeperTrails.size(); k++) {
            if (counter % this.trailResolution == 0) {
                pvecList.add(creeperTrails.get(k));
            }
            counter++;
        }
        if (pvecList.size() > 0) {
            for (int j = 0; j < pvecList.size(); j++) {
                if (j != 0) {
                    List<PVector> vecList = new ArrayList<PVector>();
                    ArrayList colList = new ArrayList();
                    PVector pos = pvecList.get(j);
                    PVector prevpos = pvecList.get(j - 1);
                    vecList.add(pos);
                    vecList.add(prevpos);
                    trailData.add(j - 1, vecList);
                    if (this.applyColor) {
                        if (this.dual && this.currentCount >= this.creeperCollection.size() / 2) {
                            int a = toneMapA.getARGBToneFor(j / (1.0f * pvecList.size()));
                            float value = map(j / (1.0f * pvecList.size()), 0, 1.0f, 0, this.strokeWidth);
                            float value2 = map(j / (1.0f * pvecList.size()), 0, 1.0f, 10, this.transparency);
                            colList.add(value);
                            colList.add(a);
                            colList.add(value2);
                        } else if (this.dual && this.currentCount < this.creeperCollection.size() / 2) {
                            int a = toneMapB.getARGBToneFor(j / (1.0f * pvecList.size()));
                            float value = map(j / (1.0f * pvecList.size()), 0, 1.0f, 0, this.strokeWidth);
                            float value2 = map(j / (1.0f * pvecList.size()), 0, 1.0f, 10, this.transparency);
                            colList.add(value);
                            colList.add(a);
                            colList.add(value2);
                        } else {
                            int a = toneMapA.getARGBToneFor(j / (1.0f * pvecList.size()));
                            float value = map(j / (1.0f * pvecList.size()), 0, 1.0f, 0, this.strokeWidth);
                            float value2 = map(j / (1.0f * pvecList.size()), 0, 1.0f, 10, this.transparency);
                            colList.add(value);
                            colList.add(a);
                            colList.add(value2);
                        }
                        trailColors.add(j - 1, colList);
                    }
                }
            }
        }
    }
    static public final float map(float value, float istart, float istop, float ostart, float ostop) {
        return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
    }
}
JAVA IMPROVED PERLIN NOISE CLASS
package creeper_Behavior_P3_2_3D_SET3;

public final class ImprovedPerlinNoise {
       static public double noise(double x, double y, double z) {
          int X = (int)Math.floor(x) & 255,                  // FIND UNIT CUBE THAT
              Y = (int)Math.floor(y) & 255,                  // CONTAINS POINT.
              Z = (int)Math.floor(z) & 255;
          x -= Math.floor(x);                                // FIND RELATIVE X,Y,Z
          y -= Math.floor(y);                                // OF POINT IN CUBE.
          z -= Math.floor(z);
          double u = fade(x),                                // COMPUTE FADE CURVES
                 v = fade(y),                                // FOR EACH OF X,Y,Z.
                 w = fade(z);
          int A = p[X  ]+Y, AA = p[A]+Z, AB = p[A+1]+Z,      // HASH COORDINATES OF
              B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z;      // THE 8 CUBE CORNERS,

          return lerp(w, lerp(v, lerp(u, grad(p[AA  ], x  , y  , z   ),  // AND ADD
                                         grad(p[BA  ], x-1, y  , z   )), // BLENDED
                                 lerp(u, grad(p[AB  ], x  , y-1, z   ),  // RESULTS
                                         grad(p[BB  ], x-1, y-1, z   ))),// FROM  8
                         lerp(v, lerp(u, grad(p[AA+1], x  , y  , z-1 ),  // CORNERS
                                         grad(p[BA+1], x-1, y  , z-1 )), // OF CUBE
                                 lerp(u, grad(p[AB+1], x  , y-1, z-1 ),
                                         grad(p[BB+1], x-1, y-1, z-1 ))));
       }
       static double fade(double t) { return t * t * t * (t * (t * 6 - 15) + 10); }
       static double lerp(double t, double a, double b) { return a + t * (b - a); }
       static double grad(int hash, double x, double y, double z) {
          int h = hash & 15;                      // CONVERT LO 4 BITS OF HASH CODE
          double u = h<8 ? x : y,                 // INTO 12 GRADIENT DIRECTIONS.
                 v = h<4 ? y : h==12||h==14 ? x : z;
          return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v);
       }
       static final int p[] = new int[512], permutation[] = { 151,160,137,91,90,15,
       131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
       190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
       88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
       77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
       102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
       135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
       5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
       223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
       129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
       251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
       49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
       138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
       };
       static { for (int i=0; i < 256 ; i++) p[256+i] = p[i] = permutation[i]; }
    }

Update
CULEBRA INTERFACE CLASS
package creeper_Behavior_P3_2_3D_SET3;
import processing.core.PApplet;
import controlP5.*;

public class Culebra_Interface extends PApplet {

    int w, h;
    PApplet parent;
    ControlP5 cp5;
    int abc = 100;
    public Knob Blend, MBaseSpeed, MSpeed, MaxRep,MaxAtt,Att,Rep,MaxConn,ConnDist;
    public RadioButton behavior, spawn, dimension;
    public CheckBox checkFlockBox, checkPerlinBox;

    public Culebra_Interface(PApplet _parent, int theWidth, int theHeight) {
        super();
        parent = _parent;
        w = theWidth;
        h = theHeight;
        PApplet.runSketch(new String[] { this.getClass().getName() }, this);
    }
    public void settings() {
        size(w, h);
    }
    public void setup() {
        surface.setLocation(10, 10);
        cp5 = new ControlP5(this);
        cp5.setColorForeground(color(0, 255, 0));
        cp5.setColorValueLabel(color(255, 255, 255));
        cp5.setBackground(color(0, 0, 0));
        cp5.setColorActive(color(0, 255, 0));
        cp5.setColorBackground(color(50, 50, 50));

        Button b0 = cp5.addButton("SPAWN CONTROLS").plugTo(parent).setPosition(10, 10).setSize(100, 20);
        
        b0.setColorActive(color(0, 255, 0));
        b0.setColorBackground(color(255, 0, 0));
        float[] spawn_default = new float[3];
        spawn_default[0] = 0.0f;
        spawn_default[1] = 1.0f;
        spawn_default[2] = 0.0f;
        spawn = cp5.addRadioButton("spawnType").setPosition(10, 40).setSize(20, 9).addItem("ALIGNED_LEFT", 0)
                .addItem("SCATTERED", 1).addItem("SCATTERED GROUND", 2).setArrayValue(spawn_default);

        Button b01 = cp5.addButton("BEHAVIOR CONTROLS").plugTo(parent).setPosition(120, 10).setSize(100, 20);
        b01.setColorActive(color(0, 255, 0));
        b01.setColorBackground(color(255, 0, 0));
        float[] beh_default = new float[5];
        beh_default[0] = 1.0f;
        beh_default[1] = 0.0f;
        beh_default[2] = 0.0f;
        beh_default[3] = 0.0f;
        beh_default[4] = 0.0f;
        behavior = cp5.addRadioButton("behaviorType").setPosition(120, 40).setSize(20, 9).addItem("FLOCKING", 0)
                .addItem("PERLIN", 1).addItem("HYBRID", 2).addItem("MODIFIEDPERLIN", 3).addItem("DUAL", 4)
                .setArrayValue(beh_default);

        Button b02 = cp5.addButton("DIMENSION CONTROLS").plugTo(parent).setPosition(230, 10).setSize(100, 20);
        b02.setColorActive(color(0, 255, 0));
        b02.setColorBackground(color(255, 0, 0));
        
        Button b03 = cp5.addButton("BOUNDS").plugTo(parent).setPosition(340, 10).setSize(275, 20);
        b03.setColorActive(color(0, 255, 0));
        b03.setColorBackground(color(255, 0, 0));
        
        Slider s20 = cp5.addSlider("BoundsWidth").plugTo(parent).setRange(100, 5000).setPosition(340, 40)
                .setValue(1000.00f).setDecimalPrecision(2).setSize(200, 10);
        Slider s21 = cp5.addSlider("BoundsDepth").plugTo(parent).setRange(100, 5000).setPosition(340, 60)
                .setValue(1000.00f).setDecimalPrecision(2).setSize(200, 10);
        Slider s22 = cp5.addSlider("BoundsHeight").plugTo(parent).setRange(100, 5000).setPosition(340, 80)
                .setValue(1000.00f).setDecimalPrecision(2).setSize(200, 10);
    
        float[] dim_default = new float[2];
        dim_default[0] = 1.0f;
        dim_default[1] = 0.0f;
        dimension = cp5.addRadioButton("dimension").setPosition(230, 40).setSize(20, 9).addItem("2D", 0)
                .addItem("3D", 1).setArrayValue(dim_default);

        Slider s2 = cp5.addSlider("Velocity").plugTo(parent).setRange(0, 50).setPosition(10, 95).setValue(1.5f)
                .setDecimalPrecision(1).setSize(200, 10);
    
        Button b = cp5.addButton("FLOCKING CONTROLS").plugTo(parent).setPosition(10, 110).setSize(270, 20);
        b.setColorActive(color(0, 255, 0));
        b.setColorBackground(color(255, 0, 0));
        
        Button bz = cp5.addButton("TAILCHASERS CONTROLS").plugTo(parent).setPosition(290, 110).setSize(320, 20);
        bz.setColorActive(color(0, 255, 0));
        bz.setColorBackground(color(255, 0, 0));
        
        cp5.addToggle("Connect").plugTo(parent).setPosition(10, 135).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("F_Bounds").plugTo(parent).setPosition(70, 135).setSize(50, 10).setValue(true)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Bounce_Rebirth").plugTo(parent).setPosition(130, 135).setSize(50, 10).setValue(true)
                .setMode(ControlP5.SWITCH);

        cp5.addToggle("Tail_Chaser").plugTo(parent).setPosition(200, 135).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);

        Slider s3 = cp5.addSlider("SearchRadius").plugTo(parent).setRange(0, 500).setPosition(10, 165).setValue(30.0f)
                .setDecimalPrecision(2).setSize(200, 10);
        Slider s4 = cp5.addSlider("AlignValue").plugTo(parent).setRange(0.00f, 1.00f).setPosition(10, 185)
                .setValue(0.045f).setDecimalPrecision(3).setSize(200, 10);
        Slider s5 = cp5.addSlider("SeparateValue").plugTo(parent).setRange(0.00f, 1.00f).setPosition(10, 205)
                .setValue(0.09f).setDecimalPrecision(3).setSize(200, 10);
        Slider s6 = cp5.addSlider("CohesionValue").plugTo(parent).setRange(0.00f, 1.00f).setPosition(10, 225)
                .setValue(0.25f).setDecimalPrecision(3).setSize(200, 10);
        
        Slider s7B = cp5.addSlider("Trail_ViewAngle").plugTo(parent).setRange(0.00f, 360.00f).setPosition(290, 165)
                .setValue(60.0f).setDecimalPrecision(3).setSize(200, 10);
        Slider s8B = cp5.addSlider("Follow_Coh_Range").plugTo(parent).setRange(0.00f, 500.00f).setPosition(290, 185)
                .setValue(20.0f).setDecimalPrecision(3).setSize(200, 10);
        Slider s9B = cp5.addSlider("Follow_Coh_Mag").plugTo(parent).setRange(0.00f, 1.00f).setPosition(290, 205)
                .setValue(0.5f).setDecimalPrecision(3).setSize(200, 10);
        Slider s10B = cp5.addSlider("Follow_Sep_Range").plugTo(parent).setRange(0.00f, 500.00f).setPosition(290, 225)
                .setValue(5.00f).setDecimalPrecision(3).setSize(200, 10);
        Slider s11B = cp5.addSlider("Follow_Sep_Mag").plugTo(parent).setRange(0.00f, 1.00f).setPosition(290, 245)
                .setValue(1.00f).setDecimalPrecision(3).setSize(200, 10);
        MaxRep = cp5.addKnob("Max_Rep", 0.0f, 10.0f, 10.0f, 290, 260, 40);
        MaxAtt = cp5.addKnob("Max_Att", 0.0f, 1.0f, 0.05f, 340, 260, 40);
        Rep = cp5.addKnob("Repulsion", 0.0f, 10.0f, 5.0f, 390, 260, 40);
        Att = cp5.addKnob("Attraction", 0.0f, 10.0f, 1.0f, 440, 260, 40);
        cp5.addToggle("Enable_Influence").plugTo(parent).setPosition(290, 135).setSize(50, 10).setValue(false)
        .setMode(ControlP5.SWITCH);
        ConnDist = cp5.addKnob("ConnDist", 0.0f, 500.0f, 30.0f, 490, 260, 40);
        MaxConn = cp5.addKnob("MaxConn", 0.0f, 300.0f, 20.0f, 540, 260, 40);

        Button b4 = cp5.addButton("PERLIN CONTROLS").plugTo(parent).setPosition(10, 320).setSize(270, 20);
        b4.setColorActive(color(0, 255, 0));
        b4.setColorBackground(color(255, 0, 0));

        Slider ps3 = cp5.addSlider("Multiplier").plugTo(parent).setRange(0, 10).setPosition(10, 375).setValue(0.0f)
                .setDecimalPrecision(2).setSize(200, 10);
        Slider ps4 = cp5.addSlider("Strength").plugTo(parent).setRange(0.00f, 100.00f).setPosition(10, 395)
                .setValue(7.00f).setDecimalPrecision(3).setSize(200, 10);
        Slider ps5 = cp5.addSlider("Scale").plugTo(parent).setRange(0.00f, 1000.00f).setPosition(10, 415)
                .setValue(800.00f).setDecimalPrecision(3).setSize(200, 10);
        Slider ps6 = cp5.addSlider("Mod_Mult").plugTo(parent).setRange(0.00f, 100.00f).setPosition(10, 435)
                .setValue(10.00f).setDecimalPrecision(3).setSize(200, 10);
        cp5.addToggle("Bounds").plugTo(parent).setPosition(10, 345).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Mod_Type_0").plugTo(parent).setPosition(70, 345).setSize(50, 10).setValue(true)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Mod_Type_1").plugTo(parent).setPosition(130, 345).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Mod_Type_2").plugTo(parent).setPosition(190, 345).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        
        Button b5 = cp5.addButton("VIZ CONTROLS").plugTo(parent).setPosition(10, 450).setSize(270, 20);
        b5.setColorActive(color(0, 255, 0));
        b5.setColorBackground(color(255, 0, 0));
        cp5.addToggle("ApplySweetColor").plugTo(parent).setPosition(10, 475).setSize(50, 10).setValue(true)
                .setMode(ControlP5.SWITCH);
        Slider s7 = cp5.addSlider("HeadWidth").plugTo(parent).setRange(0.00f, 8.0f).setPosition(10, 505).setValue(1.0f)
                .setDecimalPrecision(2).setSize(200, 10);
        Slider s8 = cp5.addSlider("StrokeWidth").plugTo(parent).setRange(0.00f, 10).setPosition(10, 525).setValue(3.0f)
                .setDecimalPrecision(2).setSize(200, 10);
        Slider s9 = cp5.addSlider("Transparency").plugTo(parent).setRange(0.00f, 255).setPosition(10, 545)
                .setValue(255.0f).setDecimalPrecision(2).setSize(200, 10);
        Slider s10 = cp5.addSlider("Count").plugTo(parent).setRange(0.00f, 50000).setPosition(10, 565).setValue(500)
                .setDecimalPrecision(0).setSize(200, 10);

        Slider s12 = cp5.addSlider("TrailResolution").plugTo(parent).setRange(1.00f, 50.00f).setPosition(10, 585)
                .setValue(1.00f).setDecimalPrecision(1).setSize(200, 10);
        
        Button b6 = cp5.addButton("HYBRID CONTROLS").plugTo(parent).setPosition(10, 600).setSize(270, 20);
        b6.setColorActive(color(0, 255, 0));
        b6.setColorBackground(color(255, 0, 0));
        Blend = cp5.addKnob("Blend", 0.0f, 1.0f, 0.5f, 10, 630, 40);
        MBaseSpeed = cp5.addKnob("Init Speed", 0.0f, 10.0f, 1.0f, 70, 630, 40);
        MSpeed = cp5.addKnob("MaxSpeed", 0.0f, 15.0f, 2.0f, 130, 630, 40);
        cp5.addToggle("Mod_Perlin").plugTo(parent).setPosition(190, 630).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        Button m0a = cp5.addButton("MAP BEHAVIORS").plugTo(parent).setPosition(10, 690).setSize(270, 20);
        m0a.setColorActive(color(0, 255, 0));
        m0a.setColorBackground(color(255, 0, 0));
        cp5.addToggle("ApplyMap").plugTo(parent).setPosition(10, 720).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("ShowMap").plugTo(parent).setPosition(70, 720).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Boundary").plugTo(parent).setPosition(130, 720).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        cp5.addToggle("Bounce_Spawn").plugTo(parent).setPosition(190, 720).setSize(50, 10).setValue(false)
                .setMode(ControlP5.SWITCH);
        Button m0 = cp5.addButton("FLOCKING MAP BEHAVIOR").plugTo(parent).setPosition(10, 750).setSize(250, 20);
        this.checkFlockBox = cp5.addCheckBox("checkBox").setPosition(10, 780).setColorForeground(color(120))
                .setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10).setItemsPerRow(3)
                .setSpacingColumn(60).setSpacingRow(20).addItem("Align", 0.0f).addItem("Separate", 0.0f)
                .addItem("Cohesion", 0.0f);
        Button m01 = cp5.addButton("NOISE MAP BEHAVIOR").plugTo(parent).setPosition(10, 800).setSize(250, 20);

        this.checkPerlinBox = cp5.addCheckBox("checkBoxPerlin").setPosition(10, 830).setColorForeground(color(120))
                .setColorActive(color(255)).setColorLabel(color(255)).setSize(20, 10).setItemsPerRow(3)
                .setSpacingColumn(60).setSpacingRow(20).addItem("StrengthVal", 0.0f).addItem("ScaleVal", 0.0f)
                .addItem("MultiplierVal", 0.0f);
        Button resetIt = cp5.addButton("RESET").plugTo(parent).setPosition(10, 850).setSize(250, 40);
        resetIt.setColorActive(color(0,255,0));
        resetIt.setColorBackground(color(255,255,0));
        resetIt.setColorLabel(color(0));

        s2.setColorActive(color(255, 0, 0));
        s3.setColorActive(color(255, 0, 0));
        s4.setColorActive(color(255, 0, 0));
        s5.setColorActive(color(255, 0, 0));
        s6.setColorActive(color(255, 0, 0));
        s7.setColorActive(color(255, 0, 0));
        s8.setColorActive(color(255, 0, 0));
        s9.setColorActive(color(255, 0, 0));
        s10.setColorActive(color(255, 0, 0));
        s12.setColorActive(color(255, 0, 0));
        s21.setColorActive(color(255, 0, 0));
        s22.setColorActive(color(255, 0, 0));
        ps3.setColorActive(color(255, 0, 0));
        ps4.setColorActive(color(255, 0, 0));
        ps5.setColorActive(color(255, 0, 0));
        ps6.setColorActive(color(255, 0, 0));
    }
    public void draw() {
        background(0);
    }
}
Update

 

  • Share

Leave a reply

Your email address will not be published. Required fields are marked *