1

Processingスケッチに遅延を挿入しようとしています。試してみThread.sleep()ましたが、Java のように描画のレンダリングが妨げられるため、うまくいかないと思います。

基本的には、三辺を描くのに遅れをとって三角形を描かなければなりません。

それ、どうやったら出来るの?

4

2 に答える 2

3

処理プログラムは、コンピュータの時計の値を読み取ることができます。現在の秒は、second()関数で読み取られ、0 から 59 の値が返されます。現在の分は、minute() 関数で読み取られこれも 0 から 59 の値が返されます

その他の時計関連関数: millis()day()month()year()

これらの数値は、前述の本から引用した次の処理スケッチのように、イベントをトリガーし、時間の経過を計算するために使用できます。

// Uses millis() to start a line in motion three seconds 
// after the program starts

int x = 0;

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

void draw() {
  if (millis() > 3000) {
    x++;
    line(x, 0, x, 100);
  }
}

以下は、3 秒ごとに辺が描画される三角形の例です (三角形は 1 分ごとにリセットされます)。

int i = second();

void draw () {
  background(255);
  beginShape();
  if (second()-i>=3) {
    vertex(50,0);
    vertex(99,99);
  }
  if (second()-i>=6) vertex(0,99);
  if (second()-i>=9) vertex(50,0);
  endShape();
}
于 2013-06-10T21:21:03.060 に答える
2

@ user2468700 が示唆するように、時間管理機能を使用してください。millis()が好きです。

特定の間隔で時間を追跡する値と現在の時刻 (継続的に更新される) がある場合は、遅延/待機値に基づいて、一方のタイマー (手動で更新されるもの) が他方のタイマー (継続的なもの) より遅れているかどうかを確認できます。その場合は、データ (この場合は描画するポイントの数) を更新し、最後にローカルのストップウォッチのような値を更新します。

これは基本的なコメント付きの例です。レンダリングは、理解しやすくするためにデータの更新から分離されています。

//render related
PVector[] points = new PVector[]{new PVector(10,10),//a list of points
                                 new PVector(90,10),
                                 new PVector(90,90)};
int pointsToDraw = 0;//the number of points to draw on the screen
//time keeping related
int now;//keeps track of time only when we update, not continuously
int wait = 1000;//a delay value to check against

void setup(){
  now = millis();//update the 'stop-watch'
}
void draw(){
  //update
  if(millis()-now >= wait){//if the difference between the last 'stop-watch' update and the current time in millis is greater than the wait time
    if(pointsToDraw < points.length) pointsToDraw++;//if there are points to render, increment that
    now = millis();//update the 'stop-watch'
  }
  //render
  background(255);
  beginShape();
  for(int i = 0 ; i < pointsToDraw; i++) {
    vertex(points[i].x,points[i].y);
  }
  endShape(CLOSE);
}
于 2013-06-10T22:51:23.233 に答える