def draw(screen, now): w, h = screen.get_size() sunrise, noon, sunset = [((t - time.timezone) / 3600) % 12 for t in horology.sun_events(now, lon, lat)] local_now = now - time.timezone minutes = (local_now / 60) % 60 hours = (local_now / 3600) % 12 draw_dial(screen) xo = w // 2 yo = h // 2 ro = 0.04 * min(w, h) a = hours / 12 r = 0.22 * min(w, h) x, y = artoxy(a, r, xo, yo) points = (x, y), artoxy(a - 0.25, ro, xo, yo), artoxy(a + 0.25, ro, xo, yo) gfxdraw.filled_polygon(screen, points, fg) a = minutes / 60 r *= 1.61803 x, y = artoxy(a, r, xo, yo) points = (x, y), artoxy(a - 0.25, ro, xo, yo), artoxy(a + 0.25, ro, xo, yo) gfxdraw.filled_polygon(screen, points, fg) gfxdraw.filled_circle(screen, xo, yo, int(ro), fg) r = 0.25 * min(w, h) a = sunrise / 12 x, y = artoxy(a, r, xo, yo) gfxdraw.filled_circle(screen, x, y, int(0.25 * ro), fg) a = sunset / 12 x, y = artoxy(a, r, xo, yo) gfxdraw.filled_circle(screen, x, y, int(0.25 * ro), fg)
t = 0 print """#include <inttypes.h> #include "sun.h" /* struct sun_day { uint8_t uh; uint8_t um; uint8_t dh; uint8_t dm; }; */ const struct sun_day sun_up_down[] = {""" for m in range(0, 13): for d in range(0, 32): try: t = time.mktime(time.strptime("2012-%02d-%02d 12:00" % (m, d), "%Y-%m-%d %H:%M")) except ValueError: pass up, noon, down = horology.sun_events(t, lon, lat) print format(up, down) print "};"