// // // Polygon clock // // displays the time in 6 polygons // // by Nico Daams, www.IIIxII.com // 21-10-2008 // void draw() { // white bgcolor background(255); // clock size size(400,300); // anti-aliasing on smooth(); // get time int s = second(); // Values from 0 - 59 int m = minute(); // Values from 0 - 59 int h = hour(); // Values from 0 - 23 // seconds String seconds = "0"; if ((s > 0) && (s<10)){ seconds = "0"+Integer.toString(s); } else if (s>0 ){ seconds = Integer.toString(s); } String seconds1 = "0"; String seconds2 = "0"; if (seconds != "0") { seconds1 = seconds.substring(0,1); seconds2 = seconds.substring(1); } // minutes String minutes = "0"; if ((m > 0) && (m<10)){ minutes = "0"+Integer.toString(m); } else if (m > 0){ minutes = Integer.toString(m); } String minutes1 = "0"; String minutes2 = "0"; if (minutes != "0") { minutes1 = minutes.substring(0,1); minutes2 = minutes.substring(1); } // hours String hours = "0"; if ((h > 0) && (h < 10)){ hours = "0"+Integer.toString(h); } else if (h > 0){ hours = Integer.toString(h); } String hours1 = "0"; String hours2 = "0"; if (hours != "0") { hours1 = hours.substring(0,1); hours2 = hours.substring(1); } // polygon radius for first digit int r1 = 50; // polygon radius for second digit int r2 = 40; // polygon color for first digit color color1 = color(170); // polygon color for second digit color color2 = color(100); // draw hours drawdigit(hours1, r1, 70, 150, color1); drawdigit(hours2, r2, 70, 150, color2); // draw minutes drawdigit(minutes1, r1, 200, 150, color1); drawdigit(minutes2, r2, 200, 150, color2); // draw seconds drawdigit(seconds1, r1, 330, 150, color1); drawdigit(seconds2, r2, 330, 150, color2); } // draw one single polygon void drawdigit (String value, int radius, int cx, int cy, color fillcolor) { int n = Integer.parseInt(value); if (n == 0 ) { // at zero, draw a nice circle (100 segments) n=100; } stroke(fillcolor); strokeWeight(6); strokeCap(ROUND); strokeJoin(ROUND); fill(fillcolor); beginShape(); float iter = TWO_PI / n; float theta; for(theta = 0.0; theta < TWO_PI; theta += iter) { vertex(cx - (cos(theta) * radius), cy + (sin(theta) * radius)); vertex(cx - (cos(theta + iter) * radius), cy + (sin(theta + iter) * radius)); } endShape(); } void setup(){ }