We are about to switch to a new forum software. Until then we have removed the registration on this forum.
/**
* Countdown Class (v1.2.5)
* GoToLoop (2017/Aug/26)
*
* Forum.Processing.org/two/discussion/27733/
* countdown-class-library-for-java-js-python
*
* Forum.Processing.org/two/discussion/23846/
* time-delay-in-python-mode#Item_11
*
* Gist.GitHub.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21
*/
import gotoloop.countdown.Countdown;
static final float SECS = 7.5;
static final int WAIT_TIME = (int) (SECS * 1000);
static final String AWAIT = "Awaiting " + SECS;
static final String END = "Countdown Finished";
static final color WAITING_BG = PImage.BLUE_MASK | PImage.ALPHA_MASK;
static final color DONE_BG = PImage.RED_MASK | PImage.ALPHA_MASK;
final Countdown countdown = new Countdown(WAIT_TIME);
void setup() {
size(300, 180);
smooth(3);
frameRate(60);
colorMode(RGB);
fill(#FFFF00);
textSize(0100);
textAlign(CENTER, CENTER);
final int m = millis(), t = m + WAIT_TIME;
countdown.start();
println(m, t, t - m, TAB, countdown);
}
void draw() {
getSurface().setTitle(countdown.done? END : AWAIT);
background(countdown.done? DONE_BG : WAITING_BG);
final String txt = millis() + "\n" + frameCount;
text(txt, width>>1, height>>1);
}
/**
* Countdown Class (v1.2.5)
* GoToLoop (2017/Aug/26)
*
* https://Forum.Processing.org/two/discussion/27733/
* countdown-class-library-for-java-js-python
*
* https://Forum.Processing.org/two/discussion/23846/
* time-delay-in-python-mode#Item_11
*
* https://Gist.GitHub.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21
*/
package gotoloop.countdown;
import java.util.Timer;
import java.util.TimerTask;
public class Countdown {
protected static final Timer t = new Timer("Countdown");
public TimerTask task;
public int delay;
public volatile boolean done = true;
public Countdown() {
}
public Countdown(final int waitTime) { // milliseconds
delay = Math.abs(waitTime);
}
@Override public String toString() {
return "Delay: " + delay + " - Done: " + done;
}
public Countdown start() {
if (task != null) task.cancel();
done = false;
t.schedule(task = new Timeout(), delay);
return this;
}
protected class Timeout extends TimerTask {
@Override public void run() {
done = true;
}
}
}
Comments
p5.js JS Version:
http://Bl.ocks.org/GoSubRoutine/1a0d21828319cf18fecf44101764bd60
"index.html":
"sketch.js":
"countdown.js":
Python Mode Version based on java.util.Timer
https://Gist.GitHub.com/GoToLoop/a476ac6a01d18700240853fed33c0e57
"CountdownClass.pyde":
"countdown.py":
Python Mode Version based on threading.Timer
https://Gist.GitHub.com/GoToLoop/893dc18856a7842b76a92d8aea837da1
"CountdownClass2.pyde":
"countdown.py":
Thxs for sharing @GoToLoop.
Kf