Question

I'm new to processing, but I'm basically trying to get this effect:

Waiting.

(1 second later)

Waiting..

(1 second later)

Waiting...

(1 second later)

Waiting....

(Then reset)

Waiting.

As a text();

Any ideas how I would be able to achieve this?

Was it helpful?

Solution

Use millis() instead, it counts the time, in milliseconds since program have started. Here a simple counter example:

edited the code again for a better example

PFont font;
String time = "000";
int initialTime;
int interval = 1000;
int fontSize;

void setup()
{
  size(300, 300);
  fontSize = 40;
  font = createFont("Arial", fontSize);
  background(255);
  fill(0);
  smooth();
  noStroke();
  textFont(font);
  initialTime = millis();
}

void draw()
{
  background(255);

  // if current time minus lastStored bigger than interval 
  if (millis() - initialTime > interval){

    // increment time as an int and back to string again
    time = nf(int(time) + 1, 3);

    // reset counter
    initialTime = millis();
  }

  // just  cosmetic using the counter ...
  if (int(time) % 5 != 0) {
    fill(210);
  }else{
    fill(170, 100, 100);
  }

  ellipse(width/2, height/2, 120, 120);

  fill(255);
  ellipse(width/2, height/2, 100, 100);


  //display time
  fill(0);
  text(time, width/2 - textWidth(time)/2, height/2 + fontSize/2.8 );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top