xxxxxxxxxx
76
//I want to imitate the orbit of the comet around the solar system to make a clock. In reality, the clock is basically round. In order to "draw" the orbits of the planets, I used ARC and Map to draw a basic sector, which can change according to time. Then I draw the boundaries with stroke. Next I used Nofill to cancel the filling inside the arc to draw the basic orbits. In order to make the Angle change and data input more convenient, I used angleMode(DEGREES) at the beginning. I also tried to make an alarm clock with if else, which would remind me to get ready for class whenever classes started at 9 o 'clock. At other times I would be reminded to listen to teachers and do homework. But I didn't find out the way to draw a comet in front of the orbit.
function setup() {
createCanvas(600, 600);
angleMode(DEGREES); //angle
}
function draw() {
background(50);
translate(300, 300);
rotate(-90);
let h = hour();
let m = minute();
let s = second();
strokeWeight(6);
noFill();
//second
stroke(255,66,93);
let secondAngle = map(s, 0, 60, 0, 360);
arc(0, 0, 500, 196, 0, secondAngle); //500*(1-0.618)
//minute
stroke(144,247,255);
let minuteAngle = map(m, 0, 60, 0, 360);
arc(0, 0, 188, 480, 0, minuteAngle); // 480*(1-0.618)
//hour
stroke(199,237,233);
let hourAngle = map(h, 0, 12, 0, 360);
arc(0, 0, 160, 160, 0, hourAngle);
//second
push();
rotate(secondAngle);
strokeWeight(3.7);
stroke(255,66,93);
line(0, 0, 65, 0);
pop();
//minute
push();
rotate(minuteAngle);
strokeWeight(3.7);
stroke(144,247,255);
line(0, 0, 40.17, 0);
pop();
//hour
push();
rotate(hourAngle);
strokeWeight(3.7);
stroke(199,237,233);
line(0, 0, 24.83, 0);
pop();
//middle point
strokeWeight(10);
stroke(255);
point(0, 0);
//alarm clock
if (h == 20 && m >= 55) {
console.log('Ready for class!!! Do it! Just do it!');
} else {
console.log('Listen carefully in class!!!/Do your homework well!!!');
}
}