I am trying to use the flood fill algorithm to fill in one of the two colors of this curve, which is defined with red being 1 and blue being zero. However, when I try to run my code, it says that the syntax for the line if m[i][j]=1:
is incorrect. Any advice on how to debug this? Thanks. In this code m
is the matrix I am working in and i
and j
are my xy variables
from pylab import *
m=zeroes((100,100))
for i in range(100):
for j in range(100):
m[i,j]=sin(i+j+0.1*i*j+0.1*j*j)+cos(i-j+0.2*i*i)
n=m.copy()
n[n>0]=1
n[n<0]=0
imshow(n)
def floodfill (m,i,j):
if m[i][j]=1:
m[i][j]=0
if i>0:
floodfill(matrix,i-1,j)
if i < len(m[y]) - 1:
floodfill(m, i+1, j)
if j>0:
floodfill(m, i, j-1)
floodfill(m, i, j-1)