Saturday, September 7, 2013

Set frame rate of draw()

This example set frame rate (2 frames per second) by calling frameRate() in setup(). Also display the duration between draw() called. After frame rate set, draw() will be called in around 500ms.

Set frame rate of draw()
Set frame rate of draw()


long lastTime;

void setup() {
  size(300, 200);
  lastTime = System.currentTimeMillis() - lastTime;
  
  frameRate(2);  //set 2 frames/sec
}

void draw() { 
  long curTime = System.currentTimeMillis();
  long duration = curTime - lastTime;
  lastTime = curTime;
  println(duration);
}

No comments:

Post a Comment