multiple varying frameRates within a Processing window.

edited October 2013 in How To...

I am creating an application that requires different frameRates for different "animations" I am triggering in the window. Specifically, I have an array of images I am cycling through to create an animation, but I have this happening throughout different coordinates of the window.

I want to section off a particular frameRate for a certain animation. Is their a method to run simultaneously different framerates without effecting the entire program?

here is an interesting paper discussing this:citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.9435&rep=rep1&type=pdf

Answers

  • Answer ✓

    Basically, no. What you would do instead is remove all calls to framerate, and have certain sections update using different timers. Here's an example:

    float timer1 = 0;
    float timer2 = 0;
    float delay1 = 1000/60f; // 60 fps
    float delay2 = 1000/20f; // 20 fps
    
    void setup(){
      size(400,200);
      noStroke();
    }
    
    void draw(){
      if( millis() > timer1 ){
        fill(random(255),random(255),random(255));
        rect(0,0,200,200);
        timer1+=delay1;
      }
      if( millis() > timer2 ){
        fill(random(255),random(255),random(255));
        rect(200,0,200,200);
        timer2+=delay2;
      }
    }
    
  • Ah, perfect. Thanks a bunch.

  • Or use %

    if (frameCount % 2)
      // Animate every other frame
    
    if (frameCount % 3)
      // Animate one frame out of three
    

    But that's less precise and less fine grained that the solution given by TfGuy44.

  • Thanks, PhiLho.

    I'm not sure I understand why it is less precise. Could you elaborate?

  • edited October 2013 Answer ✓

    Function frameRate() sets the FPS for draw() calls. And its default value is 60.
    And variable frameCount stores how many times draw() was invoked!

    However, there's no guarantee that draw()'s gonna finish on time to get a specified FPS.
    So, that FPS is just an attempt. While mills() is independent from all that! (~~)

    Anyways, if we don't need "surgical" precision, frameCount is totally usable! :bz

  • Answer ✓

    I would also never use framerate(FPS) to control the speed of animations, just keep it at 60 (or even 30 for a big program).

  • Answer ✓

    Beside what GoToLoop said, it is also less precise in the sense that you can set the millisecond interval to an arbitrary value, while if you use % you are stuck to multiples of the base frame rate. May not be a problem, depending on your needs.

Sign In or Register to comment.