Anonymous Anonymous - 6 months ago
581 0

Tower clock

C

BLUBb

PImage img;  // Declare variable "a" of type PImage

void setup() {
  size(1024, 579);
  // The image file must be in the data folder of the current sketch 
  // to load successfully
  img = loadImage("Keele-University-Library-5.jpg");  // Load the image into the program  
}

void draw() {
  // Displays the image at its actual size at point (0,0)
  image(img, 0, 0);
  // Displays the image at point (0, height/2) at half of its size
  fill(80);

  noStroke();

  // Angles for sin() and cos() start at 3 o'clock;

  // subtract HALF_PI to make them start at the top

 //map function use to set a range of intergers

  float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI; // two pi-half pi = 360-90

  float m = map(minute(), 0, 60, 0, TWO_PI) - HALF_PI;

  float h = map(hour() % 12, 0, 12, 0, TWO_PI) - HALF_PI;

  stroke(255); //colour of the lines

  strokeWeight(1); // weight of lines

  line(502, 118, cos(s) * 14 + 502, sin(s) * 14 + 118);

  strokeWeight(2);

  line(502, 118, cos(m) * 10 + 502, sin(m) * 10 + 118);

  strokeWeight(3);

  line(502, 118, cos(h) * 6 + 502, sin(h) * 6 + 118);

}