-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill_color.py
More file actions
40 lines (30 loc) · 857 Bytes
/
fill_color.py
File metadata and controls
40 lines (30 loc) · 857 Bytes
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
from graphics import *
from sys import setrecursionlimit
setrecursionlimit(18000)
win = GraphWin("Filling the Colors in Life", 600, 600)
win.setBackground("Black")
def getColor(x, y):
overlapping = win.find_overlapping(x, y, x+1, y)
if overlapping:
return win.itemcget(overlapping[-1], "fill")
else:
return color_rgb(0, 0, 0)
def floodFill(x, y):
color = getColor(x, y)
print(color)
if color == "#000000":
win.plotPixel(x, y, "White")
floodFill(x + 1, y)
floodFill(x - 1, y)
floodFill(x + 1, y + 1)
floodFill(x + 1, y - 1)
floodFill(x - 1, y + 1)
floodFill(x - 1, y - 1)
floodFill(x, y + 1)
floodFill(x, y - 1)
def drawCircle():
Circle(Point(200, 200), 100).draw(win)
floodFill(200, 200)
drawCircle()
win.getMouse()
win.close()