(How to implement a timer thread in your Processing sketch)
---------------------
Thread thread1; // thread for timer
boolean tick;
void setup() {
size(400, 300);
tick = false;
thread1 = new Thread(new timerThread());
thread1.start();
}
void draw() {
background(255);
if (tick) line(10, 10, 100, 10);
else line(10, 10, 10, 100);
}
// thread for 1 sec. timer
class timerThread implements Runnable {
public synchronized void run() {
while (true) {
try{
Thread.sleep(1000);
} catch (InterruptedException e) {}
tick = !tick;
}
}
}
0 件のコメント:
コメントを投稿