diff --git a/Webserver/src/routes/clock/+page.svelte b/Webserver/src/routes/clock/+page.svelte index 73e9e1c..0c8a891 100644 --- a/Webserver/src/routes/clock/+page.svelte +++ b/Webserver/src/routes/clock/+page.svelte @@ -7,16 +7,22 @@ body: number; // Clock hand radii hands: { + second: number; minute: number; hour: number; }; // Clock time percentages time: { + second: number; minute: number; hour: number; }; // Clock hand positions positions?: { + second: { + x: number; + y: number; + }; minute: { x: number; y: number; @@ -34,10 +40,12 @@ const clock: Clock = { body: 48, hands: { + second: 45, minute: 40, hour: 25 }, time: { + second: 0, minute: 0, hour: 0 }, @@ -47,8 +55,8 @@ const TWO_PI = 2 * Math.PI; const HALF_PI = Math.PI / 2; - function calcPos(time: 'minute' | 'hour', operation: 'sin' | 'cos') { // Calculate (x = r * cos(a), y = r * sin(a)) + function calcPos(time: 'second' | 'minute' | 'hour', operation: 'sin' | 'cos') { const radius = clock.hands[time]; const angle = TWO_PI * clock.time[time]; const relative = Math[operation](angle - HALF_PI); @@ -56,17 +64,20 @@ return 50 + radius * relative; } - function update() { - const current = new Date(); - const time = current.toTimeString(); - const [hour, minute, _] = time.split(' ')[0].split(':'); + async function update() { // Update time variables + const current = new Date(Date.now()); clock.time = { - hour: Number(hour) / 12, - minute: Number(minute) / 60 + second: current.getSeconds() / 60, + minute: current.getMinutes() / 60, + hour: (current.getHours() % 2) / 12 }; // Update hand positions clock.positions = { + second: { + x: calcPos('second', 'cos'), + y: calcPos('second', 'sin') + }, minute: { x: calcPos('minute', 'cos'), y: calcPos('minute', 'sin') @@ -79,7 +90,6 @@ } onMount(() => { - update(); setInterval(update, clock.speed * 1000); }); @@ -89,6 +99,16 @@ + + +