# Can I stop the animation but still change amount of tiles?

**URL:** <https://discourse.processing.org/t/can-i-stop-the-animation-but-still-change-amount-of-tiles/37209>\
**Category:** Coding Questions\
**Created:** [May 29, 2022, 5:58pm UTC](https://discourse.processing.org/t/can-i-stop-the-animation-but-still-change-amount-of-tiles/37209 "2022-05-29T17:58:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![friedadedoncker](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@friedadedoncker](https://discourse.processing.org/u/friedadedoncker)\
**Post date:** [May 29, 2022, 5:58pm UTC](https://discourse.processing.org/t/can-i-stop-the-animation-but-still-change-amount-of-tiles/37209/1 "2022-05-29T17:58:46Z")

</div>

Can I, in this example of code, somehow stop the animation of the tiles changing but still be able to change the amount of tiles (with an Arduino pot)?  
If yes, how?

Right now, when I stop the loop, the ability to change anything else disappears.

Thanks!

```auto
//GRID
   tilesX = serialInArray[0];
  tilesY = serialInArray[1];

  float tileW = width / tilesX;
  float tileH = height / tilesY;

  for (int x = 0; x<tilesX; x++) {
    for ( int y = 0; y<tilesY; y++) {
      int posX = int(tileW *x);
      int posY = int(tileH *y);

   
      //WAVE ROOD
      float wave = cos(radians(frameCount *x +y));
      float mappedWave = map(wave, -1, 1, 0, 16);
      int selector = int(mappedWave);

      //GRID ROOD
      pushMatrix();

     
      translate(posX, posY);
      if (selector == 0) {
        fill(#ff0000);
        rect(0, 0, tileW, tileH);
        //image(img, 200, 0, tileW, tileH);
      } else if (selector == 1) {
        fill(#ff0000);
        rect(0, 0, tileW, tileH);
        // image(img, width/2, height/2, tileW, tileH);
      } else if (selector == 2) {
        push();
        //noFill();
        rect(0, 0, tileW, tileH);
        pop();
      } else if (selector == 3) {
        fill(#ff0000);
        arc(0, 0, tileW*2, tileH*2, radians(0), radians(90));
      } else if (selector == 4) {
        fill(#ff0000);
        arc(tileW, 0, tileW*2, tileH*2, radians(90), radians(180));
      } else if (selector == 5) {
        fill(#ff0000);
        arc(tileW, tileH, tileW*2, tileH*2, radians(180), radians(270));
      } else if (selector == 6) {
        fill(#ff0000);
        arc(0, tileH, tileW*2, tileH*2, radians(270), radians(360));
      } else if (selector == 7) {
        fill(#ff0000);
        ellipse(tileW/2, tileH/2, tileW, tileH);
      } else if (selector == 8) {
        fill(#ff0000);
        triangle(0, tileH, 0, 0, tileW, tileH);
      } else if (selector == 9) {
        fill(#ff0000);
        triangle(0, tileH, tileW, 0, tileW, tileH);
      } else if (selector == 10) {
        fill(#ff0000);
        triangle(0, 0, tileW, 0, tileW, tileH);
      } else if (selector == 11) {
        fill(#ff0000);
        triangle(0, 0, tileW, 0, 0, tileH);
      } else if (selector == 12) {
        fill(#ff0000);
        arc(tileW/2, 0, tileW, tileH, radians(0), radians(180));
      } else if (selector == 13) {
        fill(#ff0000);
        arc(tileW/2, tileH, tileW, tileH, radians(180), radians(360));
      } else if (selector == 14) {
        fill(#ff0000);
        arc(tileW/2, tileH/2, tileW, tileH, radians(90), radians(270));
      } else if (selector == 15) {
        fill(#ff0000);
        arc(0, tileH/2, tileW, tileH, radians(270), radians(450));
      }
     popMatrix();

```

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [May 29, 2022, 8:32pm UTC](https://discourse.processing.org/t/can-i-stop-the-animation-but-still-change-amount-of-tiles/37209/2 "2022-05-29T20:32:26Z")

</div>

If your pot value works by polling the input, then you will have to leave Processing looping in order to keep testing the input. The alternative is to have an event callback such as how keyPressed() works and have it call redraw() while otherwise in noLoop().

For polling, put your drawing code in its own function and, from draw(), only call that function when your pot value changes. So, create a global variable that remembers the last pot value. draw() then checks if the current pot value is different and if so, remember the new value and redraw by calling your function.

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [May 30, 2022, 4:32am UTC](https://discourse.processing.org/t/can-i-stop-the-animation-but-still-change-amount-of-tiles/37209/3 "2022-05-30T04:32:52Z")

</div>

Try making the float ‘wave’ a global variable, also create a global boolean for a paused state

```auto
boolean paused;
float wave;

```

then have in your for loops

```auto
if (paused == false){
  wave = cos(radians(frameCount * x + y));
}

```

then use a key press for the paused state.

```auto
void keyPressed(){
  if (key == ' '){
    paused = !paused;
  }
}

```

this is a simple way to have the spacebar be a pause button without interfering with all the other stuff, if you need it to pause other parts just apply the same if statement there, you could also use a mousePressed function instead of the keyPressed

hope that helps
