Skip to content

Instantly share code, notes, and snippets.

@tomrockdsouza
Last active November 27, 2017 17:07
Show Gist options
  • Save tomrockdsouza/641d8e6bb6f56ac4220b2036d83ee96c to your computer and use it in GitHub Desktop.
Save tomrockdsouza/641d8e6bb6f56ac4220b2036d83ee96c to your computer and use it in GitHub Desktop.
Stack based Flood Fill algorithm in Python
row=int(input())
col=int(input())
xpoint=int(input())
ypoint=int(input())
mult = row * col
p=[]
def isPrime(num):
for x in reversed(range(2,num)):
if num%x==0 and num>1 :
return 1
return 0
for x in range(mult):
p.append(isPrime(x))
width=col
height=row
def getpixel(row,col):
return p[row*width+col]
def printArray():
for rowx in range(height):
for coly in range(width):
print(getpixel(rowx,coly),end=" ")
print()
def number(row,col):
return row*width+col
z=[]
def tomfilleralgo(row,col,color,inputcolor):
x=getpixel(row,col)
if x==color:
print("Hi")
p[number(row,col)]=inputcolor
if (row>0):
f1=[row-1,col]
if not f1 in z:
z.append(f1)
tomfilleralgo(f1[0],f1[1],color,inputcolor)
if (row<height-1):
f2=[row+1,col]
if not f2 in z:
z.append(f2)
tomfilleralgo(f2[0],f2[1],color,inputcolor)
if (col<width-1):
f3=[row,col+1]
if not f3 in z:
z.append(f3)
tomfilleralgo(f3[0],f3[1],color,inputcolor)
if (col>0):
f4=[row,col-1]
if not f4 in z:
z.append(f4)
tomfilleralgo(f4[0],f4[1],color,inputcolor)
printArray()
print()
tomfilleralgo(xpoint,ypoint,getpixel(xpoint,ypoint),2)
z=[]
print(z)
printArray()
'''
need to keep a handy pixel pool
need to keep a array for drawd checking CGPoint
need a function that continously edits the array and keeps a lock
need a function to write the modified buffer to the UIImage
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment