Skip to content

Commit

Permalink
Version 2.0 - Overweening Chronograph
Browse files Browse the repository at this point in the history
  • Loading branch information
loraxipam committed Jan 27, 2022
1 parent 803033d commit e4eb4c5
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application.*/
81 changes: 52 additions & 29 deletions Duoclock.pde
Original file line number Diff line number Diff line change
@@ -1,82 +1,105 @@
/**
* A Duodecimal Clock.
*
* (c) 2021, loraxipam@github.com
* (c) 2022 loraxipam@github.com
*
* The current time can be read with the second(), minute(),
* and hour() functions. In this example, sin() and cos() values
* are used to set the position of the hands.
* Is duodecimal not to the clock as chocolate to red wine?
*
* This is the resizable "Overweening Chronograph" 2.0 version.
*
* MIT Licensed
*/

int cx, cy;
int cx, cy, prr, crr, radius;
float secondsRadius;
float minutesRadius;
float hoursRadius;
float clockDiameter;
PFont f;

void setup() {
// the "current radius ratio," crr, is based on this size
size(384, 384);
prr = 1; crr = 1;
surface.setResizable(true);
frameRate(2);
//size(384, 384, P3D);
//smooth(3);
stroke(255);

int radius = min(width, height) / 2;
secondsRadius = radius * 0.72;
minutesRadius = radius * 0.66;
hoursRadius = radius * 0.55;
clockDiameter = radius * 1.8;

cx = width / 2;
cy = height / 2;

f = loadFont("LiberationSansNarrow-12.vlw");
textFont(f, 16);
f = loadFont("LiberationSansNarrow-16.vlw");
textFont(f, 16 * crr);
}

void draw() {
background(0);

radius = min(width, height) / 2;
crr = 2 * radius / 384;
secondsRadius = radius * 0.75;
minutesRadius = radius * 0.666;
hoursRadius = radius * 0.55;
clockDiameter = radius * 1.8;
char[] hr = {'6','8','A','0','2','4','6','8','A','0','2','4'};

cx = width / 2;
cy = height / 2;

// Draw the clock background
fill(32);
noStroke();
ellipse(cx, cy, clockDiameter, clockDiameter);
// the "night" side
fill(0);
arc(cx, cy, secondsRadius*2, secondsRadius*2, 0, PI);
arc(cx, cy, secondsRadius * 2, secondsRadius * 2, 0, PI);

// Load a new size font if the window has changed scale
if (crr != prr) {
prr = crr;
// we only go up to 4x
if (crr > 3) {
f = loadFont("LiberationSansNarrow-64.vlw");
} else if (crr < 2) {
f = loadFont("LiberationSansNarrow-16.vlw");
} else if (crr == 2) {
f = loadFont("LiberationSansNarrow-32.vlw");
} else {
f = loadFont("LiberationSansNarrow-48.vlw");
}
textFont(f, 16 * crr);
}

// Draw the numbers
fill(128);
char[] hr = {'6','8','A','0','2','4','6','8','A','0','2','4'};
for (int t = 0; t < 12; t ++) {
float rx, ry, tRadius;
tRadius=secondsRadius+16;
rx=cos(radians(t*30))*tRadius;
ry=sin(radians(t*30))*tRadius;
text(hr[t], cx-4+rx, cy+4+ry);
// Push the labels out a bit
tRadius = secondsRadius * 1.125;
// This is where they need to go
rx = cos(radians(t * 30)) * tRadius;
ry = sin(radians(t * 30)) * tRadius;
// Write them
text(hr[t], cx-4*crr+rx, cy+4*crr+ry);
if (t < 3 || t > 8) {
text('1', cx-12+rx, cy+4+ry);
text('1', cx-12*crr+rx, cy+4*crr+ry);
}
}

// Angles for sin() and cos() start at "3 o'clock"
// subtract 3PI/2 to make them start at the bottom
float sec, min, hor;
sec=second(); min=minute(); hor=hour();
sec = second(); min = minute(); hor = hour();
float s = map(sec, 0, 60, 0, TWO_PI) - radians(270);
float m = map(min + norm(sec, 0, 60), 0, 60, 0, TWO_PI) - radians(270);
float h = map(hor + norm(min, 0, 60), 0, 24, 0, TWO_PI) - radians(270);

// Draw the hands of the clock
stroke(255);
strokeWeight(2);
strokeWeight(2+2*crr);
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
strokeWeight(4);
strokeWeight(4+4*crr);
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
strokeWeight(1);
strokeWeight(1+crr);
// second hand is red
stroke(255,0,0);
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
Expand All @@ -90,9 +113,9 @@ void draw() {
float x = cx + cos(angle) * secondsRadius;
float y = cy + sin(angle) * secondsRadius;
if (a % 30 == 0) {
strokeWeight(4); // useless with P2D
strokeWeight(4+2*crr); // useless with P2D
} else {
strokeWeight(2);
strokeWeight(2+1*crr);
}
vertex(x, y);
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Processing3 should be able to compile this for just about any place you want to run it.

Version 2.0 now with refreshing, resizable window geometry. Go full screem[sic]!!

## Action shots

Enjoy the shiny 2D goodness below.
Expand Down
Binary file removed data/LiberationSansNarrow-12.vlw
Binary file not shown.
Binary file added data/LiberationSansNarrow-16.vlw
Binary file not shown.
Binary file added data/LiberationSansNarrow-32.vlw
Binary file not shown.
Binary file added data/LiberationSansNarrow-48.vlw
Binary file not shown.
Binary file added data/LiberationSansNarrow-64.vlw
Binary file not shown.

0 comments on commit e4eb4c5

Please sign in to comment.