logo

[P]rolebra.0.9B1

Projects details

Download App – prolebra.0.9B1

prolebra processing behavior library beta tests

 

MAIN APP
MAIN - With Imported Creeper Library
import toxi.color.*;
import toxi.math.*;
import toxi.math.noise.*;
import toxi.physics.*;
import toxi.physics.behaviors.*;
import controlP5.*;
import toxi.geom.mesh.*;
import java.util.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.math.noise.*;
import toxi.physics.*;
import toxi.physics.behaviors.*;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.util.Calendar;
import toxi.processing.*;
//------------------Import Mode Libraries----------------------
import creeper_Behavior_P3_Solo.*;
import java.util.List;
//----------------------ClassVariables-------------------------
List<Creeper> creeperFamily; 
Creeper creeper;
//-----------------CONTROL P5 UI-----------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
boolean showGUI = false;
//Define Global Variables---------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
boolean simulate = true;
//Define Parameters---------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////
int resetCounter = 0; 
float connectivityThreshold = 0;
float Speed = 0.5;
float SearchRadius = 100;
float AlignValue = 0.25;
float SeparateValue = 100.0;
float CohesionValue = 0.35;
float HeadWidth = 3.0;
float StrokeWidth = 1.0;
float Transparency = 255.0;
float Count = 500;
boolean Connect = false;
boolean Swarm = false;
boolean Perlin = false;
boolean Hybrid = false;
boolean Bounds = false;
int TrailResolution = 6;
float Multiplier = 1.0;
float Scale, Strength, Velocity;
boolean mapVal = false;
boolean ShowMap = false;
boolean ApplyMap = false;
boolean ApplySweetColor = false;
boolean RESET = false;

RadioButton spawn, behavior, dimension; 
Knob Blend, MSpeed, MBaseSpeed;
CheckBox checkFlockBox, checkPerlinBox;
PImage img;

Culebra_Interface cI;
void settings() {
  size(1400, 1000, FX2D);
  smooth();
}
void setup() {
  if (this.resetCounter == 0) {
    cI = new Culebra_Interface(this, 400, 1025);
  }
  surface.setLocation(420, 10);
  frameRate(100);
  img = loadImage("MAP.jpg");
  simulate = true;
  creeperFamily = new ArrayList<Creeper>(); 
  for (int i = 0; i < Count; i++) {
    PVector origin = new PVector();
    PVector speed = new PVector();
    if (spawn == null || spawn.getState(0)) {
      origin = new PVector(0, random(height), 0);
      speed = new PVector(random(0, Speed), 0, 0);
    } else if (spawn != null || spawn.getState(1)) {
      origin = new PVector(random(width), random(height), 0);
      speed = new PVector(random(-Speed, Speed), random(-Speed, Speed), 0);
    }
    this.creeper = new Creeper(origin, speed, width, height);
    this.creeperFamily.add(creeper);
  }
}
void draw() {
  background(0);
  if (mapVal == true) {
    image(img, 0, 0);
  }
  this.Speed = this.MBaseSpeed.getValue();
  if (behavior.getState(0)) {
    this.Swarm = true; 
    this.Perlin = false;
  }
  if (behavior.getState(1)) { 
    this.Perlin = true;
    this.Swarm = false;
    this.Hybrid = false;
  }
  if (behavior.getState(2)) { 
    this.Perlin = false;
    this.Swarm = false;
    this.Hybrid = true;
  }
  if (!behavior.getState(0)) {
    this.Swarm = false;
  }
  if (!behavior.getState(1)) {
    this.Perlin = false;
  }
  if (!behavior.getState(2)) {
    this.Hybrid = false;
  }
  for (int i = 0; i < creeperFamily.size (); i++) {
    Creeper creep = (Creeper)creeperFamily.get(i);

    creep.applyColor = this.ApplySweetColor;
    creep.applyMap = this.ApplyMap;
    creep.img = this.img;
    creep.searchRad = SearchRadius;
    creep.av = AlignValue;
    creep.sv = SeparateValue;
    creep.cv = CohesionValue; 
    creep.swarm = Swarm;
    creep.perlin = Perlin;
    creep.bounds = Bounds;
    creep.multiplier = this.Multiplier;
    creep.scale = this.Scale;
    creep.strength = this.Strength;
    creep.velocity = this.Velocity;
    creep.blend = this.Blend.getValue();
    creep.max = this.MSpeed.getValue();
    creep.hybrid = this.Hybrid;
    creep.strokeWidth = StrokeWidth;
    creep.transparency = Transparency;
    creep.simulate = simulate;
    creep.trailResolution = TrailResolution;
    creep.creeperCollection = this.creeperFamily;
    if (this.ApplyMap) {
      creep.mapAV = this.checkFlockBox.getState(0); 
      creep.mapSV = this.checkFlockBox.getState(1);
      creep.mapCV = this.checkFlockBox.getState(2);
      creep.mapPS = this.checkPerlinBox.getState(0);
      creep.mapPSC = this.checkPerlinBox.getState(1);
      creep.mapPM = this.checkPerlinBox.getState(2);
    }
    creep.action();
    pushStyle();
    stroke(255, 255, 255); //Stroke Value
    strokeWeight(HeadWidth); //ThickLines
    point(creep.loc.x, creep.loc.y, 0);
    popStyle();
    noFill();

    if (i!=0) {
      if (creep.trailData.size() > 0) {
        for (int rr = 0; rr < creep.trailData.size (); rr++) {
          List<PVector> vecs = creep.trailData.get(rr);
          ArrayList colors = new ArrayList();
          if (this.ApplySweetColor) {
            colors = creep.trailColors.get(rr);
          }
          PVector vecA = vecs.get(0);
          PVector vecB = vecs.get(1);
          if (this.ApplySweetColor) {
            Float val = (Float) colors.get(0);
            int val2 = (Integer) colors.get(1);
            Float val3 = (Float) colors.get(2);  
            strokeWeight(val);
            stroke(val2, val3);
          } else {
            strokeWeight(1);
            stroke(255, 255);
          }
          line(vecA.x, vecA.y, vecB.x, vecB.y);
        }
      }
    }
  }
}
void RESET(boolean resetFlag) { 
  if (resetFlag) {
    this.resetCounter ++;
    setup();
  }
}
void ShowMap(boolean theFlag) {
  if (theFlag==true) {
    mapVal = true;
  } else {
    mapVal = false;
  }
}
void keyPressed() {
  if (key == 's') {
    simulate = !simulate;
  }
  if (key == 'r') {
    setup();
  }
}
Update
CULEBRA_INTERFACE
public class Culebra_Interface extends PApplet {
  int w, h;
  PApplet parent;
  ControlP5 cp5;
  int abc = 100;
  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);
    float[] spawn_default = new float[2];
    spawn_default[0] = 1.0f;
    spawn_default[1] = 0.0f;
    spawn = cp5.addRadioButton("spawnType").setPosition(10, 40).setSize(20, 9).addItem("ALIGNED_LEFT", 0).addItem("SCATTERED", 1).setArrayValue(spawn_default);

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

    Button b02 = cp5.addButton("DIMENSION CONTROLS").plugTo(parent).setPosition(230, 10).setSize(100, 20);
    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, 90).setValue(5.0).setDecimalPrecision(1).setSize(200, 20);

    Button b = cp5.addButton("FLOCKING CONTROLS").plugTo(parent).setPosition(10, 120).setSize(250, 20);
    b.setColorActive(color(0, 255, 0));
    b.setColorBackground(color(255, 0, 0));
    cp5.addToggle("Connect").plugTo(parent).setPosition(10, 180).setSize(50, 20).setValue(false).setMode(ControlP5.SWITCH);
    Slider s3 = cp5.addSlider("SearchRadius").plugTo(parent).setRange(0, 500).setPosition(10, 150).setValue(30.0).setDecimalPrecision(2).setSize(200, 20);
    Button b3 = cp5.addButton(" ").plugTo(parent).setPosition(10, 220).setSize(250, 2);
    Slider s4 = cp5.addSlider("AlignValue").plugTo(parent).setRange(0.00, 1.00).setPosition(10, 230).setValue(0.045).setDecimalPrecision(3).setSize(200, 20);
    Slider s5 = cp5.addSlider("SeparateValue").plugTo(parent).setRange(0.00, 1.00).setPosition(10, 260).setValue(0.09).setDecimalPrecision(3).setSize(200, 20);
    Slider s6 = cp5.addSlider("CohesionValue").plugTo(parent).setRange(0.00, 1.00).setPosition(10, 290).setValue(0.25).setDecimalPrecision(3).setSize(200, 20);

    Button b4 = cp5.addButton("PERLIN CONTROLS").plugTo(parent).setPosition(10, 320).setSize(250, 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, 350).setValue(0.0).setDecimalPrecision(2).setSize(200, 20);
    Button pb2 = cp5.addButton("  ").plugTo(parent).setPosition(10, 380).setSize(470, 2);
    Slider ps4 = cp5.addSlider("Strength").plugTo(parent).setRange(0.00, 100.00).setPosition(10, 390).setValue(7.00).setDecimalPrecision(3).setSize(200, 20);
    Slider ps5 = cp5.addSlider("Scale").plugTo(parent).setRange(0.00, 1000.00).setPosition(10, 420).setValue(800.00).setDecimalPrecision(3).setSize(200, 20);
    cp5.addToggle("Bounds").plugTo(parent).setPosition(10, 450).setSize(50, 10).setValue(false).setMode(ControlP5.SWITCH);

    Button b5 = cp5.addButton("VIZ CONTROLS").plugTo(parent).setPosition(10, 480).setSize(250, 20);
    b5.setColorActive(color(0, 255, 0));
    b5.setColorBackground(color(255, 0, 0));
    cp5.addToggle("ApplySweetColor").plugTo(parent).setPosition(10, 510).setSize(50, 10).setValue(true).setMode(ControlP5.SWITCH);
    Slider s7 = cp5.addSlider("HeadWidth").plugTo(parent).setRange(0.00, 8.0).setPosition(10, 540).setValue(1.0).setDecimalPrecision(2).setSize(200, 20);
    Slider s8 = cp5.addSlider("StrokeWidth").plugTo(parent).setRange(0.00, 10).setPosition(10, 570).setValue(3.0).setDecimalPrecision(2).setSize(200, 20);
    Slider s9 = cp5.addSlider("Transparency").plugTo(parent).setRange(0.00, 255).setPosition(10, 600).setValue(255.0).setDecimalPrecision(2).setSize(200, 20);
    Slider s10 = cp5.addSlider("Count").plugTo(parent).setRange(0.00, 50000).setPosition(10, 630).setValue(500).setDecimalPrecision(0).setSize(200, 20);
    Slider s12 = cp5.addSlider("TrailResolution").plugTo(parent).setRange(1.00, 50.00).setPosition(10, 660).setValue(6.00).setDecimalPrecision(1).setSize(200, 20);

    Button b6 = cp5.addButton("HYBRID CONTROLS").plugTo(parent).setPosition(10, 690).setSize(250, 20);
    b6.setColorActive(color(0, 255, 0));
    b6.setColorBackground(color(255, 0, 0));
    Blend = cp5.addKnob("Blend", 0.0, 1.0, 0.5, 10, 720, 50);
    MBaseSpeed = cp5.addKnob("Init Speed", 0.0, 10.0, 1.0, 70, 720, 50);
    MSpeed = cp5.addKnob("MaxSpeed", 0.0, 15.0, 3.0, 130, 720, 50);
    cp5.addButton("RESET").plugTo(parent).setPosition(10, 790).setSize(250, 20);
    cp5.addToggle("ApplyMap").plugTo(parent).setPosition(10, 820).setSize(50, 20).setValue(false).setMode(ControlP5.SWITCH);
    cp5.addToggle("ShowMap").plugTo(parent).setPosition(70, 820).setSize(50, 20).setValue(false).setMode(ControlP5.SWITCH);

    Button m0 = cp5.addButton("FLOCKING MAP BEHAVIOR").plugTo(parent).setPosition(10, 860).setSize(250, 20);
    m0.setColorActive(color(0, 255, 0));
    m0.setColorBackground(color(255, 0, 0));
    checkFlockBox = cp5.addCheckBox("checkBox")
      .setPosition(10, 890)
      .setColorForeground(color(120))
      .setColorActive(color(255))
      .setColorLabel(color(255))
      .setSize(20, 10)
      .setItemsPerRow(3)
      .setSpacingColumn(60)
      .setSpacingRow(20)
      .addItem("Align", 0.0)
      .addItem("Separate", 0.0)
      .addItem("Cohesion", 0.0)
      ;
    Button m01 = cp5.addButton("NOISE MAP BEHAVIOR").plugTo(parent).setPosition(10, 910).setSize(250, 20);
    m01.setColorActive(color(0, 255, 0));
    m01.setColorBackground(color(255, 0, 0));
    checkPerlinBox = cp5.addCheckBox("checkBoxPerlin")
      .setPosition(10, 940)
      .setColorForeground(color(120))
      .setColorActive(color(255))
      .setColorLabel(color(255))
      .setSize(20, 10)
      .setItemsPerRow(3)
      .setSpacingColumn(60)
      .setSpacingRow(20)
      .addItem("StrengthVal", 0.0)
      .addItem("ScaleVal", 0.0)
      .addItem("MultiplierVal", 0.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));
    ps3.setColorActive(color(255, 0, 0));
    pb2.setColorActive(color(255, 0, 0));
    ps4.setColorActive(color(255, 0, 0));
    ps5.setColorActive(color(255, 0, 0));
  }
  public void draw() {
    background(0);
  }
}
Update
JAVA CULEBRA_P3 JAR
JAVA CREEPER CLASS
package creeper_Behavior_P3;
import processing.core.*;
import java.util.ArrayList;
import java.util.List;
import toxi.color.*;
import java.util.Random;
import creeper_Behavior_P3.ImprovedPerlinNoise;
public class Creeper{
    public PVector loc;
    public PVector speed;
    private PVector acc = new PVector();
    public ArrayList<PVector> creeperTrails;
    public List<Creeper> creeperCollection;
    public List<List<PVector>> trailData;
    public List<ArrayList> trailColors;
    private float width;
    private float height;
    public float searchRad;
    public float av;
    public float sv;
    public float cv;
    public float connThresh;
    public float connect;
    public float max;
    public boolean swarm;
    public boolean perlin;
    public boolean hybrid;
    public boolean bounds;
    private boolean needsRefresh;
    public boolean applyMap;
    public boolean applyColor;
    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(1.0f / 255.0f, 53.0f / 255.0f, 103.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 ToneMap toneMapA;
    public boolean simulate;
    public float strokeWidth, transparency;
    public int trailResolution;
    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 width, float height) {
        this.loc = origin;
        this.creeperTrails = new ArrayList<PVector>();
        this.speed = speed;
        this.width = width;
        this.height = height;
        this.creeperCollection = new ArrayList<Creeper>();
        gradA.addColorAt(0.0f, colorA);
        gradA.addColorAt(255.0f, colorC);
        toneMapA = new ToneMap(0.0f, 1.0f, gradA);
    }
    // ALL FUNCTIONS
    // ---------------------------------------------------------------------------------------------------------
    public void action() {
        this.r = new Random();
        if (this.simulate) {
            if (this.swarm || (this.hybrid && this.blend == 1.0)) {        
                flocking();
                bounce();            
                this.loc.add(speed);
                this.creeperTrails.add(new PVector(loc.x, loc.y, 0));
                acc = new PVector();
            }
            if (this.perlin || (this.hybrid && this.blend == 0.0)) {
                perlinNoise();
                if (this.bounds) {
                    checkLoc();
                }
                speed = new PVector();
                speed.add(acc);
                this.loc.add(speed);
                this.creeperTrails.add(new PVector(loc.x, loc.y, 0));
                acc = new PVector();
            }
            if (this.hybrid && (this.blend != 0.0 && this.blend != 1.0)) {
                speed.add(acc);
                speed.limit(this.max);
                this.loc.add(speed);
                this.creeperTrails.add(new PVector(loc.x, loc.y, 0));
                acc = new PVector();
                perlinNoise();
                flocking();
                bounce();
            }
            if (!this.swarm && !this.perlin && !this.hybrid) {
                this.acc = new PVector(1.0f, 0, 0);
            }
            trails();
        }
    }
    private void checkLoc_B() {
        Float w = width;
        Double dW = (double) w;
        Float h = height;
        Double dH = (double) h;
        this.needsRefresh = false;
        if (loc.x > width || this.loc.x < 0 || this.loc.y > height || this.loc.y < 0) {
            this.needsRefresh = true;
        }
    }
    private void checkLoc() {
        Float w = width;
        Double dW = (double) w;
        Float h = height;
        Double dH = (double) h;
        this.needsRefresh = false;
        if (loc.x > width || this.loc.x < 0 || this.loc.y > height || this.loc.y < 0) {
            this.needsRefresh = true;
            float x = GetRandomNumbers(0.0f, dW, this.r);
            float y = GetRandomNumbers(0.0f, dH, this.r);
            this.loc = new PVector(x, y, 0);
            this.creeperTrails = new ArrayList<PVector>();
        }
    }
    // BOUNCE METHOD
    // ------------------------------------------------------------------------------------------------------------
    private void bounce() {
        if (loc.x > width) {
            speed.x = speed.x * -1;
        }
        if (loc.x < 0) {
            speed.x = speed.x * -1;
        }
        if (loc.y > height) {
            speed.y = speed.y * -1;
        }
        if (loc.y < 0) {
            speed.y = speed.y * -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;
        float fX = (float) rX;
        float fY = (float) rY;
        rando.x = fX;
        rando.y = fY;
        rando.z = 0.00f;
        return rando;
    }
    private void perlinNoise() {
        if (!this.applyMap) {
            PVector multSpeed = GetRandomNumber(-this.multiplier, this.multiplier, this.r);
            double noiseVal = ImprovedPerlinNoise.noise(this.loc.x / (Float) this.scale, this.loc.y / (Float) this.scale, 0.0)
                    * 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);
            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);
                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);
    }
    // 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.velocity);
                }
            } 
            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)));
        }
    }
    // TRAIL FUNCTION
    // ---------------------------------------------------------------------------------------------------------------------------------
    private void trails() {
        this.trailData = new ArrayList<List<PVector>>();
        this.trailColors = new ArrayList<ArrayList>();
        int counter = 0;
        List<PVector> 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){

                        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;
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

 

  • Share

Leave a reply

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