// Chess Clock // joel gillman Febuary, 2008 // Minneapolis, Minnesota // lab.joelgillman.com // Processing 0135 // User editable variables int timeLimitMin = 10; // in minutes int timeLimitSec = timeLimitMin * 60; int FPS = 30; int stage = 200; int counter = 0; boolean started = false; boolean paused = false; boolean currentPlayer = true; int player1 = 0; int player2 = 0; int s; float minuteHandLength = stage * -0.3; float secondHandLength = stage * -0.4; void reset(){ // true is player1, false is player2 started = false; paused = false; currentPlayer = true; player1 = 0; player2 = 0; drawClocks(0,0,player1); drawClocks(stage,0,player2); } void setup() { frameRate(FPS); size(400,200); smooth(); background(0); //timeLimit *= 60; drawClocks(0,0,player1); drawClocks(stage,0,player2); } void draw() { // counts seconds (rather than millis) s = millis() / 1000; tick(); if (currentPlayer) { drawClocks(0,0,player1); } else { drawClocks(stage,0,player2); } } void drawClocks(int ixp, int iyp, int time) { float halfway = stage / 2; int seconds = int(map(time,0,timeLimitSec,timeLimitSec,0))%60; pushMatrix(); translate(ixp, iyp); noStroke(); fill(200); rect(0,0,stage,stage); drawTickMarks(halfway,0); drawSecondHand(halfway,seconds); drawMinuteHand(halfway,time); popMatrix(); }