topical media & game development

talk show tell print

graphic-processing-learning-10-example-10-4-example-10-4.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // example 10-4: Implementing a timer
  
  int savedTime;
  int totalTime = 5000;
  
  void setup() {
    size(200,200);
    background(0);
    savedTime = millis();
  }
  
  void draw() {
    // Calculate how much time has passed
    int passedTime = millis() - savedTime;
    // Has five seconds passed?
    if (passedTime > totalTime) {
      println( " 5 seconds have passed! " );
      background(random(255)); // Color a new background
      savedTime = millis(); // Save the current time to restart the timer!
    }
  }


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.