How do I get processing to refresh after a certain amount of time?

edited October 2013 in How To...

I want to make a decimal clock in Processing. At the moment I've

void setup(){
  size(400,400);
}

void draw(){
  background(200);
  float hour = hour()*2.4;
  float min = minute()*1.66666666666;
  float sec = second()*1.66666666666;

  textSize(32);
  text(hour , 10, 30);
  text(min , 10, 70);
  text(sec , 10, 110);
}

I think that this works but it refreshes the numbers every normal second, so I get things like 43.200h 71.667m and 7.667s Is there a way to alter this so it will update every decimal second and read exact figures? Thanks

Tagged:

Answers

  • is that what you mean?

    void draw(){
      if(second() % 10 == 0){
        println(second());
      }
    }
    
  • Hi, That's kind of what I mean. I want the decimal time to display in the window (which I've managed to do with your code) but at the moment the text disappears and the clock only reappears when the second agrees with the if statement. I'm trying to get it so that it would count like a normal clock but just in decimal time rather than normal time.

    Thanks for you help so far though! :)

  • _vk_vk
    edited October 2013

    If I understood you... Use the if statement just to set a var, not to do the actual write to the screen, like

    void draw(){
        if(second() % 10 == 0){
            //update when needed
            textToDisplay = "whatEver"; 
          }
        // display always
        text(textToDisplay, x, y);
    }
    
Sign In or Register to comment.