Counting Seconds

So to just get to the point, im wanting to make a thing that adds a "point" when every second passes. Then with another point counter that adds a "point" every 5 seconds. Im not sure how to do this so if you could give an example that would be great!

Answers

  • edited August 2017

    you could just use

    if(int(frameCount/frameRate)%seconds==0){
    addPoint();
    }
    

    the frameCount/frameRate gets the number of seconds (int so it's not a decimal) your addPoint() function might look like an array that you add coordinates to and draw them all the time (if not then they will only be drawn on every 5th or whatever second, then disappear the second after)

  • So i ran this into my code

    int seconds = second();
    
      if(int(frameCount/frameRate)%seconds==1){
        points = points + 100;
      } else {
        println(seconds);
      }
    

    but when it does not add 100 every second. and then it runs 60 times a second so when it does run it gets 1600 points. Im not sure if this is a good explanation.

  • And also what is the % used for? How does it make the thing work?

  • https://processing.org/reference/modulo.html

    You might also consider adding a point every time millis()'s value has increase by 5000:

    int time, points;
    
    void setup(){
      size(200,200);
      textAlign(CENTER);
      textSize(64);
      points = 0;
      time = millis() + 5000;
    }
    
    void draw(){
      background(0);
      fill(64);
      noStroke();
      arc( 100, 100, 180, 180, 0, map(time-millis(),0,5000,0,TWO_PI));
      fill(255);
      text( points, 100, 120);
      if( millis() > time ){
        points++;
        time = millis() + 5000;
      }
    }
    
Sign In or Register to comment.