Skip to content

Instantly share code, notes, and snippets.

@slambert
Created March 23, 2017 16:00
Show Gist options
  • Save slambert/810c775126b775e3e49b965821ff563f to your computer and use it in GitHub Desktop.
Save slambert/810c775126b775e3e49b965821ff563f to your computer and use it in GitHub Desktop.
set a time and see red flash 5 seconds later.
// Time Demo
// set a time and see red flash 5 seconds later.
// v 0.2
// Includes text on screen
// Steve is the best
// It seems he can do anything.
// March 23, 2017
int startTime = 0;
int currentTime = 0;
int endTime = 15000;
void setup() {
size(250, 250);
}
void draw() {
background(25);
println("startTime: "+startTime);
println("currentTime: "+currentTime);
println("endTime: "+endTime);
currentTime = millis();
if (currentTime >= endTime){ // if we get to the endTime....
startTime = currentTime; // it resets itself!!
endTime = currentTime + 5000; // another 5 seconds
background(255,0,0);
}
text("CURRENT TIME: " + (currentTime/1000), (width/5*1), height/2-15);
text("START TIME: " + (startTime/1000), (width/5*1), height/2);
text("END TIME: " + (endTime/1000), (width/5*1), height/2+15);
}
void keyPressed() {
if(key == 'r'){
// println("millis: "+millis()); // show me the time!
startTime = currentTime;
endTime = currentTime + 5000; // another 5 seconds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment