# How to slow down the switch in draw function?

**URL:** <https://discourse.processing.org/t/how-to-slow-down-the-switch-in-draw-function/33973>\
**Category:** Beginners\
**Created:** [December 6, 2021, 9:43pm UTC](https://discourse.processing.org/t/how-to-slow-down-the-switch-in-draw-function/33973 "2021-12-06T21:43:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![badbatman](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@badbatman](https://discourse.processing.org/u/badbatman)\
**Post date:** [December 6, 2021, 9:43pm UTC](https://discourse.processing.org/t/how-to-slow-down-the-switch-in-draw-function/33973/1 "2021-12-06T21:43:02Z")

</div>

How can I slow down the switch i’m using in draw? I’ve played with framerate and delay but it just makes the video('s) very slow which is not what I want, it still need to run smoothly.

This is the only way i’ve found out to randomize an output. If there’s any other ways in how to randommize please feel free to teach me. I just started working with Processing/Java and I’m eager to find out news ways. Thank you.

```auto
  int number = (int)(Math.random() * 4); // 0 to 100
  switch (number) {
    case 1:
      copy(video, 330, 170, 40, 40, 0, 0, video.width, video.height);
      break;
    case 2:
      copy(video, 390, 170, 40, 40, 0, 0, video.width, video.height); 
      break;
    case 3:
      copy(video, 355, 205, 40, 40, 0, 0, video.width, video.height);
      break;
    case 4:
      copy(video, 345, 230, 60, 40, 0, 0, video.width, video.height);
      break;
  }
   
  spout1.sendTexture();
  }

```

---

<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 24, 2022, 6:50am UTC](https://discourse.processing.org/t/how-to-slow-down-the-switch-in-draw-function/33973/2 "2022-05-24T06:50:06Z")

</div>

@badbatman try using

```auto
int number;

void draw() {
  if (frameCount%50 == 0) { // the 50 controls the speed of the cycling
    number = int(random(4));
    println(number);
  }
}

```

Then use that number output as your switch value;  
the % is modulo and returns the remainder of division so using it with frameCount will cycle through at a set pace, the higher that number you use with modulo the slower it will cycle

Hope that helps
