Hacker News new | past | comments | ask | show | jobs | submit login

Clock 19 shows the incorrect time for me, but it's the one I'm most interested in using. I'm diving in to the code right now, but I'm struggling to understand the math on lines 57-60 of the SVG:

    //smooth-out the rotation of the hour hand: rotate 0.008333333 of a degree every second
    hour_rotate_angle = ((30*tDate.getHours())-90)+(0.008333333*((tDate.getMinutes()*60)+tDate.getSeconds()));
    hour_hand.setAttribute("transform", "rotate("+hour_rotate_angle+",50,50)");
    hour_hand_shadow.setAttribute("transform", "rotate("+hour_rotate_angle+",50,50)");
360/0.008333333 is 43,200.

43,200 seconds equates to only 12 hours, so I'm wondering if this clock is off because it's missing 12 hours out of the day. If I half the coefficient 0.008333333 to 0.004166666, does that make it correct...

I think I just ironed out my struggle. I'm posting this before I know the result... I hope the suspense is killing you all.




Figured it out. This particular clock only uses the hour hand, but because it's a 24-hour clock, the math required is different. It looks like this snippet of code was reused from the others (12-hour clocks). The design was updated to 24-hour, but the math for the hour hand wasn't. Fortunately, the math for a 24-hour clock is simple:

360 degrees divided by the number of seconds in 24-hours (86400) gives you your rotation value: 0.004166666 degrees of rotation per second.

Now all you need to know is the number of seconds that have elapsed for the current time:

    hour_rotate_angle = (0.004166666*((tDate.getHours()*3600)+(tDate.getMinutes()*60)+tDate.getSeconds()));
If you replace lines 58 and 92 with this code, the 24-hour clock works.


You are going to be disappointed in my answer: I can't remember what I was thinking :)

I only dug out these clocks over the weekend and tweaked the home page a bit before posting it here. I haven't touched the actual Javascript or svg in over 5 yrs!

I initially posted them so they could be used with iGoogle gadgets (remember those?) The original clocks where hosted on Google sites (just to show their age :)) https://sites.google.com/site/clockamatics/

If I had to guess, that magic number is some sort of compensator to smooth out the animation, but I honestly don't remember...should be a lesson for why code should be well documented:)


I posted a reply above before refreshing the page, so I hadn't seen your reply. Hope this helps your project :)


thank you! I'll update it.


updated it:)


Yeah, that didn't do the trick. I'm not giving up though!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: