import pygame import sys # Initialize Pygame pygame.init() # Set up the canvas dimensions canvas_width = 800 canvas_height = 600 # Set up colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) # Set up the canvas canvas = pygame.display.set_mode((canvas_width, canvas_height)) canvas.fill(WHITE) # Set background color to white pygame.display.set_caption("Paint App") # Set up the brush brush_size = 10 brush_color = BLACK brush_pos = (0, 0) brush_down = False # Main loop while True: # Event handling for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: # Left mouse button brush_down = True elif event.button == 3: # Right mouse button brush_down = True brush_color = BLACK if brush_color == WHITE else WHITE # Toggle between white and black for right-click elif event.type == pygame.MOUSEBUTTONUP: if event.button == 1: brush_down = False # Draw or erase on canvas if brush_down: brush_pos = pygame.mouse.get_pos() pygame.draw.circle(canvas, brush_color, brush_pos, brush_size) # Update the display pygame.display.update() # Cap the frame rate pygame.time.Clock().tick(60)