a question about frameRate

Hello everyone,

I am playing with clock functions in processing and I was curious if Is it possible to have different frame rate for drawing different objects in a sketch? in below sketch some dots are randomly drawn in approximate place of endpoints of a clock and I want to draw each bunch of points with different speed. anyone has any idea?

Tagged:

Answers

  • int cx, cy;
    float secondsRadius;
    float minutesRadius;
    float hoursRadius;
    float clockDiameter;
    float psx, psy, pmx, pmy, phx, phy;
    void setup() {
      size(640, 640);
      stroke(255);
      frameRate(60);
      int radius = min(width, height) / 2;
      secondsRadius = radius * 0.72;
      minutesRadius = radius * 0.60;
      hoursRadius = radius * 0.50;
      clockDiameter = radius * 1.8;
    
      cx = width / 2;
      cy = height / 2;
      psx = cx;
      psy = cy;
      pmx = cx;
      pmy = cy;
      phx = cx;
      phy = cy;
    }
    
    void draw() {
      fill(255, 20);
      rect(0, 0, width, height);
    
      float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
      float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; 
      float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
    
      // Draw the points of the clock
      noStroke();
      // Seconds
      fill(#ee0000);
      psx = random(cx + cos(s) * secondsRadius - 60, cx + cos(s) * secondsRadius + 60);
      psy = random(cy + sin(s) * secondsRadius - 60, cy + sin(s) * secondsRadius + 60);  
      ellipse(psx, psy, 2, 2);
      // Minutes
      pmx = random(cx + cos(m) * secondsRadius - 40, cx + cos(m) * secondsRadius + 40);
      pmy = random(cy + sin(m) * secondsRadius - 40, cy + sin(m) * secondsRadius + 40);  
      ellipse(pmx, pmy, 2, 2);     
      // Hours
      phx = random(cx + cos(h) * secondsRadius - 20, cx + cos(h) * secondsRadius + 20);
      phy = random(cy + sin(h) * secondsRadius - 20, cy + sin(h) * secondsRadius + 20);  
      ellipse(phx, phy, 2, 2);     
    
      }
    
  • Answer ✓

    this isn't a frameRate question, Framerate is the wrong thing to use here.

    Common Questions:

    https://forum.processing.org/two/discussion/8084/how-do-i-display-a-message-for-a-few-seconds

    use a different variable for hours, minutes and seconds refresh delay.

    i'd also change

    phx = random(cx + cos(h) * secondsRadius - 20, cx + cos(h) * secondsRadius + 20);
    phy = random(cy + sin(h) * secondsRadius - 20, cy + sin(h) * secondsRadius + 20);  
    ellipse(pmx, pmy, 2, 2); 
    

    to

    phx = cx + cos(h) * secondsRadius;
    phy = cy + sin(h) * secondsRadius;  
    ellipse(pmx + random(-20, 20), pmy + random(-20, 20), 2, 2); 
    

    which is a lot neater and doesn't repeat the calls to sin / cos.

  • Answer ✓

    something like

    before setup (global)

    long lastTimeM;
    static long DELAY_M = 1000; // milliseconds between minute redraws 
    

    in draw

    long now = millis();
    // hours
    ...
    // minutes
    if (now >= lastTimeM + DELAY_M) {
      drawMinuteHand();
      lastTimeM = now;
    }
    // seconds
    ...
    
  • BUT

    draw runs 60 times a second, and that's plenty of time to redraw everything every frame using minimal cpu.

Sign In or Register to comment.