每秒添加点

时间:2012-10-30 13:13:39

标签: add processing seconds

我是处理新手,但我基本上是想要达到这个效果:

等待。

(1秒后)

等待..

(1秒后)

...等待

(1秒后)

...等待

(然后重置)

等待。

作为文本();

任何想法我将如何实现这一目标?

1 个答案:

答案 0 :(得分:2)

使用millis()代替它,它计算自程序启动以来的时间(以毫秒为单位)。这是一个简单的反例:

再次编辑代码以获得更好的示例

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 );
}
相关问题