// Kit Kat Klock - Jim Bumgardner // @pjs font="Limelight"; PFont font; int fontOffset = 24; // compensates for vertical offset bug in google font rendering // set to zero if using vlw font void setup() { size(200,500); smooth(); font = createFont("Limelight",48); textFont(font, width*.12); } void draw() { float clockRadX = width*.4; float clockRadY = width*.5; background(255); float msa = (millis() % 2000)*TWO_PI/2000; // Position of tail and eyes in cycle float am = map(minute()+second()/60.0,0,60,0,TWO_PI); // angle of minute hand, from 12 float ah = map(hour()+minute()/60.0,0,24,0,TWO_PI*2); // angle of hour hand, from 12 float mLen = width*.3; // length of hands (m,s,h) float hLen = width*.2; pushMatrix(); translate(width/2,height/2); // Much simpler if we translate to the center of the screen // Draw Head fill(0); stroke(0); strokeWeight(1); // Head Center pushMatrix(); translate(0, -width*.8); // Head ellipse(0, 0, width*.7, width*.6); // Whiskers stroke(0); strokeWeight(4); float wLen = width*.4; for (int i = 0; i < 3; ++i) { float a = radians(10 + 5*i); line(0,0, cos(a)*wLen, sin(a)*wLen); line(0,0, cos(PI-a)*wLen, sin(PI-a)*wLen); } // Muzzle fill(255); stroke(0); strokeWeight(2); arc(0, 0, width*.68, width*.58, 0, PI); fill(0); // Cheeks ellipse(-width*.175, 0, width*.35, width*.1); ellipse( width*.175, 0, width*.35, width*.1); // Nose ellipse( 0, 0, width*.2, width*.18); // Mouth strokeWeight(3); noFill(); arc(0, 0, width*.4, width*.35, PI/5, 4*PI/5); strokeWeight(1); fill(0); // Ears beginShape(); vertex(-width*.35,0); vertex(-width*.325,-width*.34); vertex(0,-width*.2); vertex(width*.325,-width*.34); vertex(width*.35,0); endShape(CLOSE); // Eyes float xd = sin(msa)*width*.05; for (int i = 0; i < 2; ++i) { pushMatrix(); translate((width*.16) * (i==0?-1:1), -width*.1); fill(255); ellipse(0, 0, width*.24, width*.24); fill(0); beginShape(); curveVertex( xd/2, -width*.09 ); curveVertex( xd/2, -width*.09 ); curveVertex( xd-5, 0 ); curveVertex( xd/2, width*.09 ); curveVertex( xd+5, 0 ); curveVertex( xd/2, -width*.09 ); curveVertex( xd/2, -width*.09 ); endShape(); popMatrix(); } popMatrix(); // end head // Tail strokeWeight(20); stroke(0); pushMatrix(); rotate(radians(sin(msa)*6)); beginShape(); for (int i = 0; i < 10; ++i) curveVertex(sin(i*TWO_PI/10.0)*10,i*height*.55/10); endShape(); popMatrix(); strokeWeight(1); // Clock Body fill(0); ellipse(0,0,clockRadX*2.1, clockRadY*2.1); noFill(); stroke(255); strokeWeight(4); ellipse(0,0,clockRadX*2, clockRadY*2); fill(0); strokeWeight(1); // Hour markers fill(255); textAlign(CENTER, CENTER); for (int i = 0; i < 12; ++i) { float a = radians(i*30); text(i==0? 12 : i, sin(a)*clockRadX*.8, fontOffset-cos(a)*clockRadY*.8); } // Minute hand fill(255,0,0); strokeWeight(.25); stroke(128); pushMatrix(); rotate(am); triangle(-5,10,0,-mLen,5,10); // draw as if it's at noon, rotation takes care of the rest popMatrix(); // Hour hand pushMatrix(); rotate(ah); triangle(-5,10,0,-hLen,5,10); // draw as if it's at noon, rotation takes care of the rest popMatrix(); // Bow Tie pushMatrix(); translate(0, -width*.5); fill(255,255,0); stroke(0); strokeWeight(2); quad(-width*.2,-width*.07, 0, -width*.04, 0, width*.04, -width*.2, width*.07); quad( width*.2,-width*.07, 0, -width*.04, 0, width*.04, width*.2, width*.07); ellipse(0,0,width*.12, width*.12); fill(0); popMatrix(); popMatrix(); }