/** * * Countdown Clock
* See time as an area instead of just a number. The size of the yellow disk * is proportional to the amout of time remaining.
* UP & DOWN arrows adjust the countdown time in 5 minute increments.
* TAB key resets the timer.

* * Created 10 April 2008 by Tim Armato
* Modified 11 April 2008
* -reorganized everything into functions
* -added reset
* -added variable countdown time
* Modified 12 April 2008
* -added remaining time display
* Modified 14 April 2008
* -size of disk now calculated by area, not diameter
* Modified 20 December 2008
* -changed seconds hand to arc() instead of a for loop of 60 lines
* -for smoother animation, converted to milliseconds instead of a frameRate(1)
* Modified 14 August 2012
* -modifying to fit iPhone 4s Retina display (960x640)

* -so far only working fo 5min setting --fixed-- * -enlarged font * -changed arrow keys to mousepressed for adjusting time sans keyboard * * Return to the blog. */ color secColor=color(200, 14, 13); color minColor=color(245, 212, 25, 210); float minCount = 5; //default number of minutes float remain = minCount; float r=300; // radius of the yellow number disk float d=r*2; // diameter of the yellow number disk float area=PI*sq(r); // calc the area //float reduce=120/(minCount*60); // how much smaller will the disk get each minute ////float reduce = area/(minCount*6000); // figure out how much area to take away each second float reduce=d/(minCount*600); // 600 is 1-minute's worth of milliseconds at 10fps float setTime=map(minCount, 0, minCount, 0, d); PFont font; void setup() { size(640, 960); fill(minColor); noStroke(); smooth(); frameRate(10); //frameRate(1); // loop draw() once per second font=loadFont("LucidaSans-TypewriterBold-18.vlw"); } void draw() { background(0); float secArc = map(millis()%60000, 0, 60000, 0, TWO_PI); // hands(second()); hands(secArc); disk(); } /////////////////// // BEGIN draw hands void hands(float s) { fill(secColor); stroke(secColor); strokeWeight(5); strokeCap(SQUARE); pushMatrix(); translate(width/2, height/2); /* for (int shizzle=0; shizzle<60-s; shizzle++){ line(0,0,0,-62); rotate(PI/30); } */ arc(0, 0, 601, 601, -PI/2, s-(PI/2)); popMatrix(); noStroke(); // resize the area once per second //area-=reduce; area=((minCount*60000)-millis())/300; if (area<0) { // if it gets to zero, area=PI*sq(r); // reset it to the fill size. } } // END draw hands /////////////////// /////////////////// // BEGIN draw disk void disk() { // main disk fill(minColor); //// float d=(sqrt(area/PI))*2; // derive the diameter from the current area // println (d+" "+setTime+" "+reduce); // ellipse(width/2,height/2,d,d); // draw a circle with that diameter setTime-=reduce; ellipse(width/2, height/2, setTime, setTime); // draw a circle with that diameter // minutes remaining // fill(secColor, 50); fill(255); textAlign(CENTER); textFont(font, 256); // base the remaining # on the diameter so it is not tied to second() text(int(remain-millis()/60000), width/2, height/2+96); // text(int(map(d,0,120,0,minCount)), width/2,height/2+10); fill(minColor); // perimeter circle stroke(minColor); strokeWeight(2); noFill(); ellipse(width/2, height/2, 600, 600); fill(minColor); } // END draw disk /////////////////// // change minCount and reset counter manually void mousePressed() { ///////////////////////// // BEGIN adjust minCount if (mouseY<=height/2) { minCount+=5; reduce=d/(minCount*600); // 600 is 1-minute's worth of milliseconds at 10fps setTime=map(minCount, 0, minCount, 0, d); //area=(minCount*60000)-millis(); //area=PI*sq(radius); remain=minCount; } if (mouseY>height/2) { minCount-=5; // area=PI*sq(r); reduce=d/(minCount*600); // 600 is 1-minute's worth of milliseconds at 10fps setTime=map(minCount, 0, minCount, 0, d); remain=minCount; } if (minCount<5) { minCount=5; //area=PI*sq(r); reduce=d/(minCount*600); // 600 is 1-minute's worth of milliseconds at 10fps setTime=map(minCount, 0, minCount, 0, d); remain=minCount; } // END minCount /////////////// }