How to resolve the algorithm Draw a clock step by step in the Processing programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Draw a clock step by step in the Processing programming language

Table of Contents

Problem Statement

Draw a clock.

More specific:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Draw a clock step by step in the Processing programming language

Source code in the processing programming language

void draw() {
  drawClock();
}
void drawClock() {
  background(192);
  translate(width/2, height/2);
  float s = second() * TWO_PI / 60.0;
  float m = minute() * TWO_PI / 60.0;
  float h = hour() * TWO_PI / 12.0;
  rotate(s);
  strokeWeight(1);
  line(0, 0, 0, -width*0.5);
  rotate(-s+m);
  strokeWeight(2);
  line(0, 0, 0, -width*0.4);
  rotate(-m+h);
  strokeWeight(4);
  line(0, 0, 0, -width*0.2);
}


int lastSec = second();
void draw() {
  if (lastSec!=second()) {
    drawClock();
    lastSec=second();
  }
}


last_sec = second()

def draw():
    global last_sec
    if last_sec != second():
        draw_clock()
        last_sec = second()

def draw_clock():
    background(192)
    translate(width / 2, height / 2)
    s = second() * TWO_PI / 60.0
    m = minute() * TWO_PI / 60.0
    h = hour() * TWO_PI / 12.0
    rotate(s)
    strokeWeight(1)
    line(0, 0, 0, -width * 0.5)
    rotate(-s + m)
    strokeWeight(2)
    line(0, 0, 0, -width * 0.4)
    rotate(-m + h)
    strokeWeight(4)
    line(0, 0, 0, -width * 0.2)


  

You may also check:How to resolve the algorithm Variable size/Get step by step in the Toka programming language
You may also check:How to resolve the algorithm Next highest int from digits step by step in the zkl programming language
You may also check:How to resolve the algorithm Time a function step by step in the Pike programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Prime triangle step by step in the Python programming language