[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] help with clock



I wrote a small clock program that I might use if it turns out well, but
I am having a small issue where the top of the arcs that grow over time
shifts when I would like it to stay still. Does anyone know how to
achieve this?
from pygame import *
import time, math
import pygame, sys


def timeintoms():
    t = time.time()
    #print t
    t %= 24*60*60 
    #print t, "Time since last day"
    t *= 1000
    #print t, "Milliseconds"
    return t

def draw_arc(surface, color,pos, radius, width, angle1, angle2):
    angle2 -= math.pi/2
    angle1 += math.pi/2
    pygame.draw.arc(surface, color, (pos[0], pos[1], radius, radius), -angle2, angle1, width)

pygame.init()
screen = pygame.display.set_mode((200,200))
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit
    screen.fill((0,0,0))
    t = timeintoms()
    s = t / 1000
    m = s / (60)
    h = m / (12)
    s %= 60
    m %= 60
    h %= 12
    #print(str(h)+":"+str(m)+":"+str(s))
    angleg = math.radians((s / 60)*360)
    angleb = math.radians((m / 60)*360)
    angleo = math.radians((h / 12)*360)
    angle1 = 0
    #print(angleg-angle1)
    draw_arc(screen, (21,176,26), (0,0), 200, 10, angle1, angleg)
    draw_arc(screen, (3,67,223), (20,20), 160, 10, angle1, angleb)
    draw_arc(screen, (249,115,6), (40,40), 120, 10, angle1, angleo)
    pygame.display.update()