How to slow down the switch in draw function?

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.

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

@badbatman try using

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

1 Like