Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- # Initialize Pygame
- pygame.init()
- # Set up display
- WIDTH, HEIGHT = 640, 480
- window = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption("Simple Paint App")
- # Set up colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- current_color = BLACK
- # Fill background with white
- window.fill(WHITE)
- # Set up variables
- drawing = False
- eraser = False
- brush_size = 5
- def draw_circle(surface, color, position, radius):
- pygame.draw.circle(surface, color, position, radius)
- def save_screenshot():
- pygame.image.save(window, "drawing.bmp")
- print("Drawing saved as 'drawing.bmp'")
- # Main loop
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- # Start drawing or erasing when mouse is pressed
- if event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1: # Left mouse button (draw)
- drawing = True
- eraser = False
- elif event.button == 3: # Right mouse button (erase)
- drawing = True
- eraser = True
- # Stop drawing when mouse is released
- if event.type == pygame.MOUSEBUTTONUP:
- if event.button in [1, 3]:
- drawing = False
- # Save drawing with 'S' key
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_s:
- save_screenshot()
- # Drawing/Erasing logic
- if drawing:
- mouse_position = pygame.mouse.get_pos()
- if eraser:
- draw_circle(window, WHITE, mouse_position, brush_size) # Erase (draw white)
- else:
- draw_circle(window, current_color, mouse_position, brush_size) # Draw black
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement