So, i have an array of “bugs” and want to make them appear inside of an ellipse and constrain them there until i release them (mouse click, probably).
My struggle right now is to make them appear inside of the ellipse.
Main Code:
// Importar Bibliotecas
import ddf.minim.*;
import processing.video.*;
PImage imgBug;
// Array de Bugs
Bug[] bugs = new Bug[5];
float raioCircunferencia;
float x;
float y;
Minim minim;
AudioInput in;
Capture cam;
void setup() {
  size(2000, 2000);
  smooth();
  raioCircunferencia = 1000;
  
  background(255);
  
  for (int i = 0; i < bugs.length; i++) {
    float a = random(TWO_PI);
    
    x = width/2+cos(a)*random(raioCircunferencia);
    x = height/2+sin(a)*random(raioCircunferencia);
    
    float r = random(50,200);
    color c = color(int(random(255)),int(random(255)),int(random(255)));
    
    bugs[i] = new Bug(c, x, y, r);
  }
  
  
  // SOM 
  minim = new Minim(this);
  minim.debugOn();
  in = minim.getLineIn(Minim.STEREO, 2048);
  
}
void draw() {
  
  stroke(1);
  fill(255);
  ellipse(width/2,height/2,raioCircunferencia,raioCircunferencia);
  
  float som = in.mix.level();
  
  fill(255,30);
  rect(0,0,width,height);
  
  
  for (int i = 0; i < bugs.length; i++) {
    bugs[i].move(som);
    bugs[i].display();
  }
}
void stop()
{
  // always close Minim audio classes when you are done with them
  in.close();
  minim.stop();
  super.stop();
}
Class Bug
class Bug {
  color c;
  color bugColor;
  float x;
  float y;
  float r;
  float speed = 2.50;
  Bug (color cor, float posX, float posY, float raio) {
    c = cor;
    x = posX;
    y = posY;
    r = raio;
  }
  void move(float audio) {
    float tx, ty;
    
    tx = x;
    ty = y;
    
    speed = map(audio, 0.00001, 1, 10, 30);
    
    tx += random(-speed, speed);
    ty += random(-speed, speed);
    
    if(tx <= 0 || tx >= width || ty <= 0 || ty >= height){
      tx = x;
      ty = y;
    }
    
    x = tx;
    y = ty;
    
  }
  void display() {
    if (x <= width/2) {
      bugColor = color(255, 0, 0);
    } 
    else {
      bugColor = color(0, 0, 255);
    }
    
    fill(bugColor);
    noStroke();
    ellipse(x, y, r, r);
  }
}

