Joanna Galia's profile

Clock for student HUB (Processing)

float z = 0.0;
PImage img1;
PImage img2;
int cx, cy;
float secondsRadius;
float minutesRadius;
float hoursRadius;
//float clockDiameter;

void setup() {
  size(displayWidth, displayHeight);
  //stroke(255);
  
  int radius = min(width, height)/2;
  secondsRadius = radius * 0.31;
  minutesRadius = radius * 0.29;
  hoursRadius = radius * 0.20;
  //clockDiameter = radius * 1.8;
  
  cx = width / 2;
  cy = height / 2;
  
  img1 = loadImage("clock.png");
  img2 = loadImage("napi.jpg");
}
void draw() {
  background(255);
  size(displayWidth, displayHeight);
  image(img2, 300, 100);
  translate(mouseX, mouseY); 
  noCursor();
  image(img1, width/2, height/2, 1100, 1100);
  imageMode(CENTER);
  
  
  // Angles for sin() and cos() start at 3 o'clock;
  // subtract HALF_PI to make them start at the top
  float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
  float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; 
  float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
  
  // Draw the hands of the clock
  stroke(255);
  strokeWeight(1);
  line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
  strokeWeight(3);
  line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
  strokeWeight(6);
  line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
  // Draw the minute ticks
  strokeWeight(2);
  beginShape(POINTS);
  for (int a = 0; a < 360; a+=6) {
    float angle = radians(a);
    float x = cx + cos(angle) * secondsRadius;
    float y = cy + sin(angle) * secondsRadius;
    vertex(x, y);
    
  }
  endShape();
  
}
Clock for student HUB (Processing)
Published:

Clock for student HUB (Processing)

Clock design for student HUB @ Edinburgh Napier. Used processing for clock.

Published: