Tag Archives: clock

Analog Clock

21 Nov

The world really doesn’t need another analog clock program, but I thought I’d make one, to illustrate why pushMatrix and popMatrix are cool. Here I’m using them to rotate each hand into the correct position.

Want some numbers instead of the minimal notches shown here? Replace the loop that draws the hour markers with this (it looks good with a 48 point font).

    // draw hour markers
    textAlign(CENTER, CENTER);
    for (int i = 0; i < 12; ++i) {
      pushMatrix();
        rotate(radians(i*30));
        pushMatrix();
        translate(0,-width*.39);
        rotate(-radians(i*30));
        text(i==0? 12 : i, 0, 0);
        popMatrix();
      popMatrix();
    }