Basic Java global variable question

roughly, this works in proccessing


//number of objects
int numbubs = 1000;

//instantiate list of objects
BubbDraw[] bubblist = new BubbDraw[numbubs]; 


void setup() {
  size(displayWidth, displayHeight);
  noStroke();
  background(0);

  //
  for (int i = 0; i < numbubs; i++) {
    bubblist[i] = new BubbDraw();
  }
}

void draw() {
  for (int i = 0; i < numbubs; i++) {
    bubblist[i].drawBubb();
  }
}

//==============================================================================

//bubble class
class BubbDraw {

  //create rgb list
  float[] rgb = new float[4];

  //initialize opacity control 
  float sizeoprange = 20;

  //initialize ellipse size step variables
  int sizestep = 1;
  int sizerange = 20;

  //constr
  BubbDraw() {
    for (int i = 0; i < 3; i++) {
      rgb[i] = random(255);
    }
    rgb[3] = random(sizeoprange);
  }//constr

  void drawBubb() {
    //color increment
    for (int i = 0; i <3; i++) {
      float randinc = second()%15;

      rgb[i] += random(-randinc, randinc);
      rgb[i] = constrain(rgb[i], 50, 255);
    }
    //opacity increment
    float sizeopstep = 0.2;
    sizeoprange += random(-sizeopstep, sizeopstep);
    sizeoprange = constrain(sizeoprange, 1, 100);
    rgb[3] = random(sizeoprange);

    fill(rgb[0], rgb[1], rgb[2], rgb[3]);

    //size increment
    sizestep = 1;
    sizerange += random(-sizestep, sizestep);
    sizerange = constrain(sizerange, 1, 40);

    float sizey = random(sizerange);
    ellipse(random(width), random(height), sizey, sizey);
  }
}//class
//

1 Like