-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (34 loc) · 1.06 KB
/
Copy pathmain.py
File metadata and controls
44 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pygame
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pygame Drawing Interface")
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BRUSH_WIDTH = 5
screen.fill(WHITE)
clock = pygame.time.Clock()
drawing = False
last_pos = None
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
screen.fill(WHITE) # clear previous stroke
drawing = True
last_pos = event.pos # starting point
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
drawing = False
last_pos = None
if drawing:
mouse_pos = pygame.mouse.get_pos()
if last_pos is not None:
pygame.draw.line(screen, BLACK, last_pos, mouse_pos, BRUSH_WIDTH)
last_pos = mouse_pos
pygame.display.flip()
clock.tick(60)
pygame.quit()