Timers

I would like to create a capture of a series of images at a dynamic frame rate based on a timer and am having a bit of trouble working with this. As of now I would signal the clock() function get that and subtract it from itself to get a beginning time then I make a statement that says if say time which is ((clock() - beginTime) % 100 == 0) capture if I wanted to take it at 10 FPS but this is bad because time is currently progressing. Is there a good way to add a listener to do this instead? So the computer would automatically signal a method call to capture the image then? I’m not much of a c++ programmer so thanks for your help.

here’s an option, using the elapsedTime and calcualting a time per frame based on your desired rate:

  
  
  
in h:   
  
float frameRateForCapture;  
float lastTime;  
  
in setup:   
  
lastTime = ofGetElapsedTimef();  
frameRateForCapture = 30; // 30 fps  
  
in update  
  
  
float timePerFrame = 1.0 / frameRateForCapture;  
float currentTime = ofGetElapsedTimef();  
if (currentTime - lastTime > timePerFrame){  
  // DO SOMETHING HERE  
  lastTime = currentTime;  
}  
  
  

this is written off the top of my head…

take care,
zach

1 Like

Here’s a quick ofxTimer add-on I started working on.

This version just includes a basic TimedCounter that will count from one number to another on a certain delay (measured in milliseconds).

This class is based on time intervals measured with ofGetElapsedTimeMillis(), so it should be safe for real-time measurement at any frame rate.

It provides hasChanged() and isCountComplete() methods for checking the status updates. I am thinking I might change this to an event system in the future, but that might actually be more confusing if there are multiple timers going at once.

There’s an example included, hopefully it’s enough :slight_smile:

ofxTimer.zip