Bubble popping animation

first a word to switch() and case.

This simple program is without it.




int stateBubble=0; 

void setup() {
  size(700, 700);
}

void draw() {
  background(0); 
  text(stateBubble, 111, 111);
}

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

void keyPressed() {
  if (key=='0')
    stateBubble = 0; 
  else if (key=='1') 
    stateBubble = 1;
  else if (key=='2') 
    stateBubble = 2;
  else {
    //ignore
  }
}
//

Here is the same Sketch with switch().

As you can see, switch() has nothing to do with state but is there to evaluate one variable when it can have different values:

Here is is used to evaluate key :



int stateBubble=0; 

void setup() {
  size(700, 700);
}

void draw() {
  background(0); 
  text(stateBubble, 111, 111);
}

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

void keyPressed() {
  switch(key) {

  case '0':
    stateBubble = 0;
    break; 

  case '1':
    stateBubble = 1;
    break; 

  case '2': 
    stateBubble = 2;
    break; 

  default:
    //ignore
    break; 
    //
  }//switch
  //
}//function 
//
1 Like