import kandinsky as kdk from time import * from math import * W,H=320,222 BLACK=(0,0,0) DARK=(20,20,20) LIGHT=(255,255,255) ACCENT=(200,150,0)#(0,200,100) GREY=(100,100,100) def fade(c1,c2,i): return tuple((int(v1*(1-i)+v2*i) for v1,v2 in zip(c1,c2))) def __fill_str(s,l,c=" "): return s+c*(l-len(s)) def draw_clock(): r,x,y=int(H//2.2),W//2,H//2 kdk.fill_rect(0,0,W,H,BLACK) kdk.draw_circle(x,y,r,ACCENT) for i in range(19): kdk.fill_circle(x,y,r-i-1,fade(BLACK,DARK,i/19)) for i in range(60): a=i/60*2*pi l=(5,20)[i%5==0] x1,y1=int(cos(a)*r),int(sin(a)*r) x2,y2=int(cos(a)*(r-l)),int(sin(a)*(r-l)) kdk.draw_line(x1+x,y1+y,x2+x,y2+y,GREY) if i%15==0: txt=str((i+15)%60) kdk.draw_string(txt,x+x2-len(txt)*3,y+y2-4,ACCENT,DARK,1) def draw_needles(t): r,x,y=int(H//3),W//2,H//2 kdk.fill_circle(x,y,int(r),(10,10,10)) min=int(t//60) sec=int(t%60) a=min/60*2*pi-pi/2 if t%1<0.5 and sec<1: a+=pi/50*sin(t*30)*(1-t%1) x1,y1=int(cos(a)*(r-2)),int(sin(a)*(r-2)) kdk.draw_line(x,y,x1+x,y1+y,LIGHT) a=sec/60*2*pi-pi/2 x1,y1=int(cos(a)*r/1.1),int(sin(a)*r/1.1) kdk.draw_line(x,y,x1+x,y1+y,ACCENT) for i in range(5): kdk.fill_circle(x+i//2,y-i//2,5-i,fade(ACCENT,LIGHT,i/5)) kdk.fill_circle(x+i//2+x1,y-i//2+y1,5-i,fade(ACCENT,LIGHT,i/5)) draw_clock() while 1: draw_needles(monotonic()) sleep(0.1)