matthewalangreen
3/26/2019 - 5:46 PM

StringList


PImage bg;
StringList imageStrings;
int index;
int y;

void setup() {
  size(640, 360);
  imageStrings = new StringList();
  // The background image must be the same size as the parameters
  // into the size() method. In this program, the size of the image
  // is 640 x 360 pixels.
  imageStrings.append("moonwalk.jpg");
  imageStrings.append("other.jpg");
  imageStrings.append("last.jpg");
}

void draw() {
  // do this when button is clicked
  // if button is clicked, choose the next background image from imageStrings
  // assign it to PImage named bg.
  // increment index
  // reset to index to 0 if we get bigger than 2
  
  if(// button is pressed) {
   index++;
   if(index > 2) {
    index = 0; 
   }
   bg = loadImage(imageStrings.get(index));
  }
  
  background(bg);
  
  stroke(226, 204, 0);
  line(0, y, width, y);
  
  y++;
  if (y > height) {
    y = 0; 
  }
}