Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Array Index Out Of Bounds Exception:0

$
0
0

I am having a problem with the below code -

it is happening at line 72: This is the line that gets highlighted when the patch crashes.

Voronoi myVoronoi = new Voronoi( points );

Has anyone any ideas what the issue is? Thank you!

import megamu.mesh.*;

// Menu GUI. Bolleans to change visualizations
boolean debug = false;
boolean view = true;
boolean info=true;
boolean voronoi=false;
boolean lines=true;

FlowField flowfield; // Flowfield object
ArrayList<Vehicle> vehicles; // An ArrayList of vehicles
int nrParticles = 300; // number of elements/particles
float[][] points = new float[nrParticles][2]; // Array for the VORONOI cells

  void setup() {
  size(1280, 720);

  // Resolution of the flowfield. nr of cells
  flowfield = new FlowField(50);

  // create the elements in a random position
  vehicles = new ArrayList<Vehicle>();
  for (int i = 0; i < nrParticles; i++) {
    vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 15), random(0.1, 1.5)));
  }

  noCursor(); // hide the mouse

  // INICIATE VORONOY STUFF
  for (int i=0; i<nrParticles; i++) {
    points[i][0]= random(800);
    points[i][1]= random(800);
  }

  //Audiostuff
  input = new AudioIn(this, 0);  //Create an Audio input and grab the 1st channel
  input.start();// start the Audio Input

  rms = new Amplitude(this); // create a new Amplitude analyze
  rms.input(input);  // Patch the input to an volume analyzer
  input.amp(1.0);

  smooth();
}

void draw() {

  //amplitude stuff
  float analise = map(rms.analyze(), 0, 0.5, 0.0, 50.0);
  audioIn+= (analise-audioIn)*0.01; //smoothing the audioIn vall

  background(0);

  flowfield.update(); // Flowfield update and display
  if (debug) flowfield.display(); // If debug mode True, display flowfield

  // Tell all the vehicles to follow the flow field
  for (Vehicle v : vehicles) {
    v.follow(flowfield);
    v.run();
  }

  // DRAWING VORONOI
  int nrVoronois=int(map(mouseY, 0, height, 0, nrParticles));

  //GETTING VEHICLES POSITION TO VORONOI'S POINTS
  for (int i=0; i<vehicles.size(); i++) {
    points[i][0]= vehicles.get(i).location.x;
    points[i][1]= vehicles.get(i).location.y;
  }

  Voronoi myVoronoi = new Voronoi( points );
  MPolygon[] myRegions = myVoronoi.getRegions();

  for (int i=0; i<nrVoronois; i++)
  {
    // an array of points
    float[][] regionCoordinates = myRegions[i].getCoords();

    fill(int(map(i*255.0, 147, i*255.0/nrParticles, 130 * (i % 2), 255)));

     //fill(int(i*255.0/nrParticles, 130 * (i % 2), 225 * (i % 2)));

//fill(255,int(map(sum[i],0,10,255,0)));  // dar valor do FFT ao interior do voronoi
    if (voronoi) myRegions[i].draw(this); // draw this shape
  }

  float[][] myEdges = myVoronoi.getEdges();

  for (int i=0; i<myEdges.length; i++)

  {
    float startX = myEdges[i][0];
    float startY = myEdges[i][1];
    float endX = myEdges[i][2];
    float endY = myEdges[i][3];
    stroke(255);
    if (lines) line( startX, startY, endX, endY
  }

Viewing all articles
Browse latest Browse all 2896

Trending Articles