Skip to content

Instantly share code, notes, and snippets.

@jsundram
Created March 12, 2012 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/2023575 to your computer and use it in GitHub Desktop.
Save jsundram/2023575 to your computer and use it in GitHub Desktop.
draw numbers on the face of a clock (text rotation, basically)
// see it live here: http://sketchpad.cc/wkAzMXfKbD
PFont font;
void setup()
{
size(600, 600);
font = loadFont("Courier", 22);
noLoop();
}
// Draw a clock, with numerals rotated to be straight-ish.
// this could be made more efficient, but it works ...
void draw()
{
background(255);
strokeWeight(1);
textFont(font, 22);
textAlign(CENTER, CENTER);
fill(0);
translate(width/2, height/2);
int n = 12;
int r = min(width/2, height/2) - 20;
float start_angle = 3*PI / 2;
for (int i = 0; i < n; i++)
{
pushMatrix();
float angle = (start_angle + i * (2*PI/n)) % (2*PI);
println(angle);
if (3*PI/2 <= angle || angle <= PI/2)
{
rotate(angle);
line(0, 0, r-w, 0);
text(i, r, 0);
}
else
{
rotate(angle + PI);
line(0, 0, w-r, 0);
text(i, -r, 0);
}
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment