I am trying to create a countdown with a circle. The circle will show how much time has passed compared to the amount of time given. So if the countdown is 10 seconds and 5 have passed, half circle will have been drawn. I've come up with this code:
from math import pi
import pygame
pygame.init()
(x, y) = (800, 600)
screen = pygame.display.set_mode((x, y))
clock = pygame.time.Clock()
radius = 50
# Just to place the circle in the center later on
top_left_corner = ((x / 2) - (radius / 2), (y / 2) - (radius / 2))
outer_rect = pygame.Rect(top_left_corner, (radius, radius))
countdown = 1000 # seconds
angle_per_frame = 2 * pi / (countdown * 60)
angle_drawn = 0
new_angle = angle_per_frame
while True:
if angle_drawn < 2 * pi:
new_angle += angle_drawn + angle_per_frame
pygame.draw.arc(screen, (255, 255, 255), outer_rect, angle_drawn, new_angle, 10)
angle_drawn += angle_per_frame
clock.tick(60)
pygame.display.update(outer_rect)
So fps = 60 and in each frame I am drawing 2 * pi / countdown * fps, dividing a full circle into frames. And then in each frame, drawing a part of the circle. It seems to draw the circle fine, but it can't be used for a timer for two reasons:
The circle seems to be completed in less time than given.
While drawing the circle, it seems like the last part of the circle is drawn faster.
Can anyone point out what I am doing wrong?