import pygame
import random
import math

# Initialize Pygame
pygame.init()

# Screen dimensions
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Moving Squares in a Circle")

# Colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)

# Square properties
square_size = 50
speed_factor = 0.1

# Circle properties
circle_center = (width // 2, height // 2)
circle_radius = 200

# Initial positions and angles
angles = [random.uniform(0, 2 * math.pi) for _ in range(2)]
velocities = [random.uniform(-speed_factor, speed_factor) for _ in range(2)]

def draw_square(x, y, color):
    pygame.draw.rect(screen, color, (x - square_size // 2, y - square_size // 2, square_size, square_size))

clock = pygame.time.Clock()
running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill(WHITE)

    for i in range(2):
        # Update angle
        angles[i] += velocities[i]
        
        # Calculate new position based on circle equation
        x = int(circle_center[0] + circle_radius * math.cos(angles[i]))
        y = int(circle_center[1] + circle_radius * math.sin(angles[i]))

        # Draw square at new position
        draw_square(x, y, RED if i == 0 else BLUE)

    pygame.display.flip()
    clock.tick(30)

pygame.quit()