MCPcopy Create free account
hub / github.com/geekcomputers/Python / update

Method update

floodfill/floodfill.py:71–118  ·  view source on GitHub ↗
(self, events)

Source from the content-addressed store, hash-verified

69 pygame.quit()
70
71 def update(self, events):
72 for ev in events:
73 if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
74 self.queue.append(ev.pos)
75
76 if not len(self.queue):
77 return
78
79 point = self.queue.pop(0)
80
81 pixArr = pygame.PixelArray(self.surface)
82
83 if pixArr[point[0], point[1]] == self.surface.map_rgb((255, 255, 255)):
84 return
85
86 pixArr[point[0], point[1]] = (255, 255, 255)
87
88 left = (point[0] - 1, point[1])
89 right = (point[0] + 1, point[1])
90 top = (point[0], point[1] + 1)
91 bottom = (point[0], point[1] - 1)
92
93 if (
94 self.inBounds(left)
95 and left not in self.queue
96 and pixArr[left[0], left[1]] == self.surface.map_rgb((0, 0, 0))
97 ):
98 self.queue.append(left)
99 if (
100 self.inBounds(right)
101 and right not in self.queue
102 and pixArr[right[0], right[1]] == self.surface.map_rgb((0, 0, 0))
103 ):
104 self.queue.append(right)
105 if (
106 self.inBounds(top)
107 and top not in self.queue
108 and pixArr[top[0], top[1]] == self.surface.map_rgb((0, 0, 0))
109 ):
110 self.queue.append(top)
111 if (
112 self.inBounds(bottom)
113 and bottom not in self.queue
114 and pixArr[bottom[0], bottom[1]] == self.surface.map_rgb((0, 0, 0))
115 ):
116 self.queue.append(bottom)
117
118 del pixArr
119
120 def inBounds(self, coord):
121 if coord[0] < 0 or coord[0] >= self.window_width:

Callers 1

runMethod · 0.95

Calls 3

inBoundsMethod · 0.95
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected