-
Notifications
You must be signed in to change notification settings - Fork 6
/
floodFill.py
66 lines (57 loc) · 1.32 KB
/
floodFill.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
from drawLine import ViewPort,bresenham
import sys,random
sys.setrecursionlimit(2*10**8)
from graphics import *
'''
100 100
50 0
100 -100
0 -50
-100 -100
-50 0
-100 100
0 50
'''
def boundaryFill(pixel,stack,filled,win,fillColor='red2'):
while(stack!=[]):
x,y=stack.pop()
if((x,y) not in pixel and (x,y) not in filled):
r=random.randint(0,255)
g=random.randint(0,255)
b=random.randint(0,255)
win.plot(x,y,color=color_rgb(r,g,b))
stack+=[(x+1,y),(x,y+1),(x,y-1),(x-1,y)]
filled.append((x,y))
def main():
vert = []
while(1):
try:
x,y=map(int,input('Next vert?').split())
vert.append((x,y))
except:
print(vert)
break
if(input('Defualt viewPort is (-400 -400, 400 400). Change?(y/Y)')in ('y','Y')):
x,y=map(int,input('viewPort\'s xMax yMax : ').split())
new_view = ViewPort(-x,-y,x,y)
else:
new_view =ViewPort(-400,-400,400,400)
print('ViewPort :',new_view)
pixel = []
filled= []
pixel_dict={}
vert+=[vert[0]]
win = new_view.init_view()
for i in range(len(vert)-1):
pixel+=bresenham(*vert[i],*vert[i+1])
for i in pixel:
x,y= i
win.plot(*i)
pixel_dict[(x,y)]=1
point = win.getMouse()
stack=[(int(point.getX()),int(point.getY()))]
#Comment this line for just polygon
boundaryFill(pixel_dict,stack,filled,win)
input('Exit?')
if __name__=='__main__':
main()