Anyone know how to Slow down my slideshow?

I am working on a slideshow that display my images repeatedly but the problem is that its showing it way too fast. How can I slow it down?

Here is my code

PImage[] images = new PImage[4]; 
int imageIndex = 0; 
int i=0;//Timer
int savedTime;
int totalTime = 3000;

void setup() { 
  size(667,700); // 
  background (0);
}

void draw() { 
  background(255);   

  ///REPEATED SLIDE SHOW////// 
  images[i] = loadImage("Visual"+i+".PNG");     
  image(images[i], 0,0);
  i++;
  if(i>3){
    i=0;
  }
}
1 Like
  • pls format your code with

</>

  • if you load the images at runtime the array makes no sense
  • you need a timer:
PImage img;
int i=0; 
long startT, totalT = 3000;

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

void draw() {
  background(200, 200, 0);
  img = loadImage("data/Visual"+i+".PNG");
  image(img, 10, 10+10*i);  // image(img,0,0);
  if ( millis() > startT + totalT ) {
    startT = millis();
    i++;
    if (i>imax)  i=0;
  }
}

with array use

int imax = 4;
PImage[] images = new PImage[imax];
int i=0; 
long startT, totalT = 3000;

void setup() {
  size(667, 700);
  for (int k = 0; k < imax; k++) images[k] = loadImage("data/Visual"+k+".PNG");
}

void draw() {
  background(200, 200, 0);
  image(images[i], 0, 0);
  myTimer();
}

void myTimer() {
  if ( millis() > startT + totalT ) {
    startT = millis();
    i++;
    if (i>=imax)  i=0;
  }
}


1 Like

Include the statement
frameRate(0.1);
in your setup to give 10 seconds per refresh.

The general solution is to size the argument “fps” in
https://processing.org/reference/frameRate_.html
as 1/(the seconds you want for the refresh delay).

2 Likes

An alternative to using a very low frameRate is to have your code execute on every nth frame – for example, every 600 frames at 60fps (10 seconds).

void draw(){
  if(frameCount%600=0){
    // redraw screen
  }
}

The nice thing about this is that your input/output (and the quit ESC key) will still be checked at 60fps, but the screen will redraw every 10 seconds. If you do it with frameRate(0.1) then it may take up to 10 seconds after you hit a key for the program to do something (e.g. quit the slideshow) – it is frozen on the draw loop.