Clock for teaching the time V1

Rupert Russell

Ballarat, Australia

  • Available
    Products
    53
  • Artist
    Notes

Apparel

Cases & Skins

Wall Art

Home Decor

Bags

Stationery

Artist's Description

// Clock face by Rupert Russell
// 31 Dec 2016

// How to calculate points on a circle
// Based on code from http://www.mathopenref.com/coordcirclealgorithm...

PFont font;
float steps = 12;

void setup() {
background(255);
font = loadFont(“ComicSansMS-Bold-248.vlw”);
size(2900, 2900); // Size of finished clock
noLoop();
smooth();
}

float clockRadius = 2900 / 2;

void draw() {
fill(100);
ellipseMode(RADIUS); // Set ellipseMode to RADIUS
strokeWeight(10);

// Draw Right side “Past” half circle and colour it yellow

fill(255, 255, 0);
arc(width/2, height/2, width * 0.49, height * 0.49, radians(-90), radians(90), PIE);

// Draw the Left side “To” half circle and colour it blue

fill(0, 0, 255);
arc(width/2, height/2, width * 0.49, height * 0.49, radians(90), radians(270), PIE);

// Divide the clock into 60 minute segments

stroke(00);
strokeWeight(5);
for (float i = 0; i < 360; i = i+( 360 / 60)) {
line(width/2, height/2, clockRadius * 0.975 * cos(radians(i + 15 )) + width/2, clockRadius * 0.975 * sin(radians(i + 15)) + height/2 );
}

// White center

fill(255);
stroke(0);
strokeWeight(2);
ellipse(width/2, height/2, width/2.3, height/2.3);

// Divide the clock into 12 hour segments

stroke(0);
strokeWeight(10);
for (float i = 0; i < 360; i = i+( 360 / steps)) {
line(width/2, height/2, clockRadius * 0.8655 * cos(radians(i + 15 )) + width/2, clockRadius * 0.8655 * sin(radians(i + 15)) + height/2 );
}

strokeWeight(10);
// Draw Right side “Past” half circle and colour it yellow
fill(255, 255, 0);
arc(width/2, height/2, width/4, height/4, radians(-90), radians(90), PIE);

// Draw the Left side “To” half circle and colour it blue

fill(0, 0, 255);
arc(width/2, height/2, width/4, height/4, radians(90), radians(270), PIE);

// Black center spot

fill(0);
stroke(0);
strokeWeight(2);
ellipse(width/2, height/2, 15, 15);

// Dashes for each hour

strokeWeight(15);
double step = radians(360) / 12;// see note 1
float h = width / 2;
float k = height /2;
float r = clockRadius / 2;

for (float theta=0; theta < 2 * PI; theta += step) {
float x1 = h + r * 1.1 * cos(theta);
float y1 = k – r * 1.1 * sin(theta); //note 2.

float x2 = h + r * 0.9 * cos(theta);
float y2 = k – r * 0.9 * sin(theta); //note 2.
line(x1, y1, x2, y2); // draw the dashes for each hour
}

// Number for each hour

int count = 13;

for (float theta = radians(90); theta < radians(420); theta += step) {
count = count – 1;

float x1 = h + r * 1.4 * cos(theta);
float y1 = k – r * 1.4 * sin(theta); //note 2.

textFont(font, 248);
textAlign(CENTER, CENTER);
text(count, x1, y1);
}

// Number for each minute to the next hour

fill(255,255,255);
int minuteCount = -1;

for (float theta=radians(90); theta < radians(270); theta += radians(360 / 60)) {
minuteCount = minuteCount + 1;

float x1 = h + r * 1.85 * cos(theta);
float y1 = k – r * 1.85 * sin(theta); //note 2.

textFont(font, 100);
textAlign(CENTER, CENTER);
text(minuteCount, x1, y1);
}

// Number for each minute past the hour

fill(0);
int minuteCountPast = 31;

for (float theta=radians(270); theta < radians(360+90); theta += radians(360 / 60)) {
minuteCountPast = minuteCountPast – 1;

float x1 = h + r * 1.85 * cos(theta);
float y1 = k – r * 1.85 * sin(theta); //note 2.

textFont(font, 100);
textAlign(CENTER, CENTER);
text(minuteCountPast, x1, y1);
}

save(“clock.png”);
exit();
}

/*
Like most graphics systems, the canvas element differs from the usual mathematical coordinate plane:

The origin is in the top left corner.
The code above compensates by assuming that h, and k are actually relative to the top left.
The y axis is inverted. Positive y is down the screen, not up. To correct for this, the k variable (the y coordinate of the center) must be positive to place the center some way down the screen.

Also the y calculation has to subtract the sin(x) term instead of add.
Marked in the code as Note 1.

Note 2. The step size is set to an exact division of 2π to avoid gaps or over-runs in the circle. This code divides the circle into exactly 20 segments.
Note too that as in most computer languages, the trig functions operate in radians, not degrees.
360° = 2π radians.
*/

desktop tablet-landscape content-width tablet-portrait workstream-4-across phone-landscape phone-portrait
desktop tablet-landscape content-width tablet-portrait workstream-4-across phone-landscape phone-portrait

10% off

for joining the Redbubble mailing list

Receive exclusive deals and awesome artist news and content right to your inbox. Free for your convenience.