int delay = 2000;
Timer timer;
int i;
void setup() {
size(400, 200);
timer = new Timer(1000); // Create a timer that goes off every 1 second
timer.start();
fill(#989696);
stroke(#747373);
rectMode(CENTER);
rect(width - 70, 35, 120, 40);
i = width - 130;
}
void draw() {
if (timer.isFinished()){
stroke(#00B4A7);
line(i, 25, i, 55);
println("Timer", i);
i++;
timer.start();
}
if (i > width - 10){
i = width - 130; //reset to your starting point
}else{
}
}
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Exercise 10-4: The raindrop catching game
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
void setTime(int t) {
totalTime = t;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if 5,000 ms have passed.
// The work of the timer is farmed out to this method.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}