Basic Java global variable question

Example


//number of objects
int numbubs = 1000;

int sizerange = 20;

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

//------

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

//initialize opacity control 
float sizeoprange = 20;

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


//------

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

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

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

void draw() {
  background(0);

  setColor();

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

//---------------------------------------------------------------

void setColor() {

  //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);
}

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

//bubble class
class BubbDraw {
  //
  float x, y; 
  float sizey = random(sizerange);

  //constr
  BubbDraw() {
    //
    x=random(width);
    y=random(height);
  }//constr

  void drawBubb() {
    ellipse(x, y, 
      sizey, sizey);
  }
}//class
//