Anonymous user
Bitmap/Flood fill: Difference between revisions
→{{header|Processing Python mode}}
Line 2,023:
<lang Python>from collections import deque
tolerance = 15▼
fill_color = color(250, 0, 0)
▲tolerance = 15
allowed = False
Line 2,042:
if allowed:
image(img, 0, 0, width, height)
text("Tolerance = {} (Use mouse wheel to change)".format(
tolerance), 100, height - 30)
text("Right click to reset", 100, height - 10)
allowed = False
def mousePressed():
global
img.loadPixels()▼
flood(mouseX, mouseY)▼
img.updatePixels()▼
allowed = True▼
if mouseButton == RIGHT:
img = loadImage("image.png")
else:
▲ img.loadPixels()
▲ flood(mouseX, mouseY)
▲ img.updatePixels()
▲ allowed = True
def mouseWheel(event):
Line 2,059 ⟶ 2,061:
e = event.getCount()
tolerance += 2 * e
if tolerance >
tolerance =
if tolerance < 0:
tolerance = 0
Line 2,067 ⟶ 2,069:
def flood(x, y):
target_color = img.pixels[pixel_position(mouseX, mouseY)]
if target_color != fill_color:
queue
queue.append((x, y))
queue.append((p_x, p_y
queue.append((p_x
queue.append((p_x
queue.append((p_x + 1, p_y))
def pixel_position(x, y):
|