import pygame import sys from imgui import PyGUI WIDTH, HEIGHT = 800, 600 class Ball: def __init__(self): self.pos = [WIDTH // 2, HEIGHT // 2] self.speed = 5 self.direction = 45 self.radius = 20 self.color = (255, 0, 0) def update(self): # (For demonstration, implement ball movement if desired.) pass def draw(self, surface): pygame.draw.circle(surface, self.color, (int(self.pos[0]), int(self.pos[1])), self.radius) def main(): pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("PyGUI Example") clock = pygame.time.Clock() PyGUI.init(screen) ball = Ball() ball_speed = ball.speed ball_direction = ball.direction ball_radius = ball.radius ball_color_r, ball_color_g, ball_color_b = ball.color bounce_enabled = False while True: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: pygame.quit() sys.exit() PyGUI.Update(events) screen.fill((50, 50, 50)) # Draw the GUI window. PyGUI.Begin("Ball Controls", 10, 10) ball_speed = PyGUI.Slider("Speed", ball_speed, 1, 10) ball_direction = PyGUI.Slider("Direction", ball_direction, 0, 360) ball_radius = PyGUI.Slider("Radius", ball_radius, 10, 100) ball_color_r = PyGUI.Slider("Red", ball_color_r, 0, 255) ball_color_g = PyGUI.Slider("Green", ball_color_g, 0, 255) ball_color_b = PyGUI.Slider("Blue", ball_color_b, 0, 255) bounce_enabled = PyGUI.Checkbox("Bounce", bounce_enabled) if PyGUI.Button("Reset Position"): ball.pos = [WIDTH // 2, HEIGHT // 2] PyGUI.End() # Update the ball parameters. ball.speed = ball_speed ball.direction = ball_direction ball.radius = int(ball_radius) ball.color = (int(ball_color_r), int(ball_color_g), int(ball_color_b)) ball.draw(screen) pygame.display.flip() clock.tick(60) if __name__ == "__main__": main()