So, I'm trying to create a fill filling algorithm, and I get a recursion error all the time. The algorithm has infinite recursion, and I cannot pinpoint why. I looked all over the Internet and I canโt find a solution, because it seems that my program is correct in accordance with most sources. However, something seems to be wrong. This is an edited version of the code. The error message is still the maximum recursion.
Can i get help?
from Tkinter import * from PIL import Image, ImageTk from random import * w= 75 h= w flood = Image.new("RGB", (w,h), (0,0,0)) x = 0 y = 0 count = 0 colorlist = [] i = 0 while x < w -1: y = 0 while y < h-1: r = random() if r < .25: flood.putpixel((x,y), (0,0,0)) else: flood.putpixel((x,y), (255,255,255)) y += 1 x += 1 x = 0 y = 0 while x < w-1: y = 0 while y < h-1: r = random() if x == 0 or y == 0 or x == w-1 or y ==h-1: flood.putpixel((x,y), (0,0,0)) y += 1 x += 1 def floodfill(x,y, d,e,f, g,h,i, image, count): count+=1 (a,b,c) = image.getpixel((x,y)) if (a,b,c) == (255,255,255): (j,k,l) = image.getpixel((x-1,y)) (m,n,o) = image.getpixel((x+1, y)) (p,q,r) = image.getpixel((x,y-1)) (s,t,u) = image.getpixel((x,y+1)) if count > 990: return if (a,b,c) == (255,255,255): image.putpixel((x,y), (g,h,i)) floodfill(x-1, y, d,e,f, g,h,i, image, count) floodfill(x+1, y, d,e,f, g,h,i, image, count) floodfill(x, y-1, d,e,f, g,h,i, image, count) floodfill(x, y+1, d,e,f, g,h,i, image,count) floodfill(2,2, 0,0,0,255,0,0,flood, 0) flood.save("flood.png") print "done"