I am currently working on creating a clock using python 2.7.5 and pygame. Here is my code so far:
screen = display.set_mode((800,600))
running=True
while running:
for e in event.get():
if e.type == QUIT:
running = False
screen.fill((0,0,0))
draw.circle(screen,(255,255,255),(400,300),100,3)
ang = 270
def clock(secs, mins, hours):
ang = 270+6*secs
dx = int(cos(radians(-ang))*100)
dy = int(sin(radians(-ang))*100)
draw.line(screen,(255,0,255),(400,300),(400+dx,300-dy),1)
time.wait(1000)
ang+=6
clock(1,1,1)
display.flip()
quit()
I am currently having problems with the adding the minutes and hours hands. What I would like to have happen I would like to be able to set any parameter(within 0,60) in the secs so that the seconds hand on the clock can begin from that point on the clock and continue to move 6 degrees clockwise from that point every second. I can currently only have either the hand moving every second but only starting from 0 degrees (the 12 on the clock) or I can have it start according to the parameters that are imputed but it does not move. I would also like to know how I would set different time.waits for different hands on the clock if that is possible. Thanks.
Working example. I use
clock.tick(1)
to wait 1 second.Use code from comments to get smoother move.
Using
get_ticks()
I can set anyFPS
and I can have second clock working 10 times faster :)Using
class
I can get more clocks :)I removed
clock.tick(60)
to get faster clocks but it makes my CPU very hot.And the same with timers (
time.set_timer()
)