class Timer { private int startTime; private int stopTime; private boolean stopped; private PFont font; Timer() { startTime = 0; stopTime = 0; font = createFont("Arial", 16); stopped = true; } void start() { startTime = millis(); stopped = false; } void stop() { stopTime = millis(); stopped = true; } int minutes() { return stopped ? (stopTime - startTime)/60000 : (millis() - startTime)/60000; } int seconds() { return stopped ? (stopTime - startTime)/1000 : (millis() - startTime)/1000; } int millisecs() { return stopped ? (stopTime - startTime) : (millis() - startTime); } void display(float x, float y, float pt, boolean centered) { String txt; textFont(font); textSize(pt); int m = minutes(); int s = seconds() - m*60; if ( s > 9 ) txt = "Time Elapsed: " + m + ":" + s; else txt = "Time Elapsed: " + m + ":0" + s; if ( centered ) text(txt, x - textWidth(txt)/2, y); else text(txt, x, y); } }