# Bubble popping animation

**URL:** https://discourse.processing.org/t/bubble-popping-animation/15341
**Category:** Beginners
**Created:** [November 8, 2019, 8:07pm UTC](https://discourse.processing.org/t/bubble-popping-animation/15341 "2019-11-08T20:07:47Z")
**Posts on this page:** 1
**Showing post:** 17

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 9, 2019, 3:00pm UTC](https://discourse.processing.org/t/bubble-popping-animation/15341/17 "2019-12-09T15:00:23Z")

</div>

first a word to switch() and case.

This simple program is **without** it.

```auto

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** :

```auto

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 
//

```

---

_[View the full topic](https://discourse.processing.org/t/bubble-popping-animation/15341)._
