PIL giving error when trying to run Floodfill, need to change to Turtle

Viewed 18

Im trying to make a BFS Floodfill with PIL, but i can't find how to fix the import erros, and I need to translate it to Python Turtle

from queue import Queue
import queue
from PIL import Image

imagen = Image.open("Imagen.png")
ROJO = (255, 0, 0)
x, y = 0, 0
floodfill(imagen, x, y, ROJO)
imagen.save("ImagenResultado.png")

def floodfill(grid, i, j, nuevo_color):
w = imagen.width
h = imagen.height
viejo_color = imagen.getpixel((x, y))

queue = Queue()
queue.put((x, y))

while not queue.empty():
    x, y = queue.get()
    if x < 0 or x >= w or y < 0 or y >= h or imagen.getpixel((x, y)) != viejo_color:
        continue
    else:
        imagen.putpixel((x, y), nuevo_color)
        queue.put((x+1,y))
        queue.put((x-1,y))
        queue.put((x,y+1))
        queue.put((x,y-1))
1 Answers
Related