-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfill.py
executable file
·88 lines (46 loc) · 1.79 KB
/
fill.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from pygame import *
screen = display.set_mode((900,675))
canvasRect = Rect(100,50,400,375)
running =True
screen.fill((255,255,255))
tool = "fill"
color = (123456)
while running:
click = False
up = False
for e in event.get():
if e.type == QUIT:
running = False
if e.type == MOUSEBUTTONDOWN:
click = True
fill_rect = draw.rect(screen,(0),(700,50,50,50),1)
draw.rect(screen,0,(200,190,90,90),1)
mb = mouse.get_pressed()
mx,my = mouse.get_pos()
draw.rect(screen,(0,0,0), canvasRect,2)
if mb[0]==1 and tool == "pen":
draw.line(screen, (0,0,0), (omx,omy),(mx,my),1)
if mb[0] == 1 and fill_rect.collidepoint(mx,my):
tool = "fill"
if tool == "fill" and click and canvasRect.collidepoint(mx,my):
fill_list = []
oldcolor = screen.get_at((mx, my))
fill_list.append((mx,my))
if color != oldcolor:
while len(fill_list) > 0:
for i in range(len(fill_list)):
cx, cy = fill_list.pop()
screen.set_at((cx, cy), color) #sets a color to a single pixel
if screen.get_at((cx+1,cy)) == oldcolor:
fill_list.append((cx+1,cy))
if screen.get_at((cx-1,cy)) == oldcolor:
fill_list.append((cx-1,cy))
if screen.get_at((cx,cy+1)) == oldcolor:
fill_list.append((cx,cy+1))
if screen.get_at((cx,cy-1)) == oldcolor:
fill_list.append((cx,cy-1))
print(tool)
omx,omy = mx,my
screen.set_clip(canvasRect)
display.flip()
quit()