Skip to content

Instantly share code, notes, and snippets.

@slambert
Created November 22, 2016 20:23
Show Gist options
  • Save slambert/3a67218b1d7ead0007334827a4f0f28b to your computer and use it in GitHub Desktop.
Save slambert/3a67218b1d7ead0007334827a4f0f28b to your computer and use it in GitHub Desktop.
This is a demo of how millis works
// Steve is the best
// It seems he can do anything.
// November 22, 2016
int startTime = 0;
int currentTime = 0;
int endTime = 15000;
void setup() {
size(512, 512);
}
void draw() {
println("startTime: "+startTime);
println("currentTime: "+currentTime);
println("endTime: "+endTime);
currentTime = millis();
// background(125);
// println("millis: "+millis()); // show me the time!
// if (millis() >= 5000) { // 5000 = 5 seconds
// background(255, 0, 0);
// }
if (currentTime >= endTime){ // if we get to the endTime....
startTime = currentTime; // it resets itself!!
endTime = currentTime + 5000; // another 5 seconds
background(random(255));
}
}
void keyPressed() {
if(key == 'r'){
// println("millis: "+millis()); // show me the time!
startTime = currentTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment