My in-laws have a clock in their kitchen that doesn’t work very well, so I was thinking about how to make it better. One of its appealing characteristics is that, sometimes, the second hand runs backwards. Unfortunately, this results in the clock failing to tell time correctly. I thought I’d prototype a better behavior for the clock in JS — because, if you can get it working in JS, you can get it working with servos, right? So this clock tells time usefully even though its hands run backwards some of the time.
I hacked this together pretty quickly one night. The entire “business logic” is really just these three angle functions:
τ * t / 3600 / 12 τ * (t / 3600 - (t % 1200 < 1170 ? 0 : t % 30 / 30)) τ * (1/2 + Math.sin(τ * t / 13.168724) / 6)
The other 38 or so lines of JS are mostly just concerned with interfacing with <canvas>, drawing a clock face, etc.