My objective is to create a function named findList()
which holds the given parameter of a point and the screen surface.
My aim is to calculate the colour of that point then return a list of the filled colour.
In example, if one had a screen with a red circle in it and the point was inside the red circle, I would like to be able to return a list holding all the points of that circle.
Basically, the point expands, avoiding all other colours and the edge of the screen until it can expand no further; in which then the function returns the list of all the created points.
Here's what I tried:
def findList(point,screen):
directions=[(0,0)]
myList=[]
myList.append(point)
startColour=screen.get_at(point)
i=0
loop=0
while True:
loop=loop+1
print(loop)
directions=[]
print("Length of myList: "+str(len(myList)))
for i in range(len(myList)):
if myList[i][0]+1<WINDOWWIDTH and screen.get_at((myList[i][0]+1,myList[i [1]))==startColour and myList[i][0]+1 not in myList and myList[i][0]+1 not in directions:
directions.append((myList[i][0]+1,myList[i][1]))
if myList[i][0]-1>0 and screen.get_at((myList[i][0]-1,myList[i][1]))==startColour and myList[i][0]-1 not in myList and myList[i][0]-1 not in directions:
directions.append((myList[i][0]-1,myList[i][1]))
if myList[i][1]+1<WINDOWHEIGHT and screen.get_at((myList[i][0],myList[i][1]+1))==startColour and myList[i][1]+1 not in myList and myList[i][1]+1 not in directions:
directions.append((myList[i][0],myList[i][1]+1))
if myList[i][1]-1>0 and screen.get_at((myList[i][0],myList[i][1]-1))==startColour and myList[i][1]-1 not in myList and myList[i][1]-1 not in directions:
directions.append((myList[i][0],myList[i][1]-1))
print(len(directions))
for i in directions:
myList.append(i)
if len(directions)==0:
break
print("Exited loop.")
return myList
I know the coding style is terrible and much of it is probably useless but the general problem is that the function(probably) works but is painstakingly slow and seems to add previously added pixels a lot until my poor little netbook can no longer cope with the 100 000 points it is working with.
It would really help me with my program if someone could make some suggestions for a better function because, being only 13, I am horribly confused with this messy bit of code (note the 4 conditions in the ifs).