Skip to content

Instantly share code, notes, and snippets.

@slambert
Created October 27, 2015 16:08
Show Gist options
  • Save slambert/b94a26fcd95ee7cc4524 to your computer and use it in GitHub Desktop.
Save slambert/b94a26fcd95ee7cc4524 to your computer and use it in GitHub Desktop.
example that combines the two earlier examples
/* A sketch that has states and a timebased slideshow
Steve Lambert October 27, 2015
v.01
Note: insert your own images to make it work.
*/
float time;
float currentTime;
int state;
PImage acapulco;
PImage acapulco2;
PImage tape;
void setup(){
size(720,500);
acapulco = loadImage("acapulco.png"); // Load the image into the program
acapulco2 = loadImage("acapulco2.png");
tape = loadImage("tape.png");
state = 0;
time = 0;
} // end setup
void draw(){
if (state == 1){
slideshow();
}
if (state == 2){
background(255,0,0);
}
if (state == 3){
image(tape, 0 , 0, 720, 480);
}
} // end draw
void keyReleased() {
if (key == 'a'){
state = 1;
}
if (key == 'r'){
state = 2;
}
if (key == 's'){
state = 3;
}
}
void slideshow(){
currentTime = millis() - time; // what it the current time?
if (currentTime > 0 && currentTime < 1000){
image(acapulco, 0 , 0, 720, 480);
}
if (currentTime > 1001 && currentTime < 2000){
image(acapulco2, 0 , 0, 720, 480);
}
if (currentTime > 2001 && currentTime < 3000){
image(tape, 0 , 0, 720, 480);
}
if (currentTime > 3001){
time = millis();
}
} // end slideshow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment