fun with clock

This commit is contained in:
Q
2024-06-03 23:18:44 +03:00
parent eef338ff64
commit 5094f5ec8f

View File

@@ -47,9 +47,11 @@ def centerpoint(ry, rx):
return (int(round(ry / 2)), int(round(rx / 2)), r) return (int(round(ry / 2)), int(round(rx / 2)), r)
def saddstr(win, y, x, s): def saddstr(win, y, x, s, a=None):
if not a:
a=curses.color_pair(0)
try: try:
win.addstr(y, x, s) win.addstr(y, x, s, a)
except: except:
pass pass
@@ -64,13 +66,13 @@ def drawcircle(win, cy, cx, r):
return return
def drawline(win, cy, cx, a, s, r, char): def drawline(win, cy, cx, a, s, r, char, attr=None):
prec = 2 prec = 2
for l in range(int(r * prec)): for l in range(int(r * prec)):
if l > s: if l > s:
ly = int(round(cy - float(l) * math.cos(a) / prec)) ly = int(round(cy - float(l) * math.cos(a) / prec))
lx = int(round(cx + 2.0 * float(l) * math.sin(a) / prec)) lx = int(round(cx + 2.0 * float(l) * math.sin(a) / prec))
saddstr(win, ly, lx, char) saddstr(win, ly, lx, char, attr)
return return
@@ -130,6 +132,10 @@ class timer_struct:
def main(): def main():
stdscr = curses.initscr() stdscr = curses.initscr()
curses.curs_set(0) curses.curs_set(0)
curses.start_color()
curses.use_default_colors()
for i in range(0, curses.COLORS):
curses.init_pair(i + 1, i, -1)
start_t = time.time() start_t = time.time()
try: try:
# rows,columns = termsize() # rows,columns = termsize()
@@ -150,9 +156,9 @@ def main():
alpham = math.pi * t_m / 30.0 + alphas / 60.0 alpham = math.pi * t_m / 30.0 + alphas / 60.0
alphah = math.pi * t_h / 6.0 + alpham / 12.0 alphah = math.pi * t_h / 6.0 + alpham / 12.0
if options.seconds: if options.seconds:
drawline(stdscr, cy, cx, alphas, 1, r / 2, "s") drawline(stdscr, cy, cx, alphas, 1, r / 2, "s", curses.color_pair(2))
drawline(stdscr, cy, cx, alpham, 1, int(round(r * 0.8) / 2), "m") drawline(stdscr, cy, cx, alpham, 1, int(round(r * 0.8) / 2), "m", curses.color_pair(3))
drawline(stdscr, cy, cx, alphah, 1, int(round(r * 0.5) / 2), "HH") drawline(stdscr, cy, cx, alphah, 1, int(round(r * 0.5) / 2), "HH", curses.color_pair(7))
stdscr.addstr(cy, cx, "o") stdscr.addstr(cy, cx, "o")
drawcircle(stdscr, cy, cx, r / 2) drawcircle(stdscr, cy, cx, r / 2)
for h in range(12): for h in range(12):