xxxxxxxxxx
67
let hrLength = 100, minLength = 125, secLength = 150;
function setup() {
createCanvas(700, 700);
angleMode(DEGREES);
}
function draw() {
background(0);
translate(width / 2, height / 2);
rotate(-90);
let hr = hour();
let mn = minute();
let sc = second();
strokeWeight(16);
stroke(255, 100, 150);
noFill();
let secondAngle = map(sc, 0, 60, 0, 360);
stroke(150, 100, 255);
let minuteAngle = map(mn, 0, 60, 0, 360);
stroke(150, 255, 100);
let hourAngle = map(hr % 12, 0, 12, 0, 360);
push();
rotate(hourAngle);
stroke(150, 255, 100);
line(0, 0, hrLength, 0);
pop();
push();
let minx = hrLength * cos(hourAngle);
let miny = hrLength * sin(hourAngle);
translate(minx, miny);
rotate(minuteAngle);
stroke(150, 100, 255);
line(0, 0, minLength, 0);
pop();
push();
let secx = minLength * cos(minuteAngle);
let secy = minLength * sin(minuteAngle);
translate(secx + minx, secy + miny);
rotate(secondAngle);
stroke(255, 100, 150);
line(0, 0, secLength, 0);
pop();
stroke(255);
point(0, 0);
rotate(90);
fill(255);
noStroke();
text(hr + ':' + mn + ':' + sc, 10, 200);
}