this is the function that gives each thumbnail it's color, I've added a list of colors chosen to compare to, t.color_bg is the color variable:
Code: Select all
def start(self, search="light"):
"""creates initial grid, with default search. """
if VERBOSE: print ("start( search={} )".format(search))
self.thumbs = []
thumb_w, thumb_h = 64, 64
numx = self.width / thumb_w
numy = self.height / thumb_h
self.caption_prepend(search)
self.thumbs = []
self.usedclr = [(0,0,0,0)] ## added
for y in range(int(numy)):
for x in range(int(numx)):
t = Thumbnail(width=self.thumb_w)
if search: t.color_bg = random_color(search)
# else: t.color_bg = Color('gray')
t.color_bg = sortdupes(self, t, search) ## added
self.usedclr.append(t.color_bg) ## added
t.fill()
t.move(thumb_w * x, thumb_h * y)
self.thumbs.append(t)Code: Select all
def sortdupes(self, t, search):
for i in range(len(self.usedclr)):
if self.usedclr[i] == t.color_bg:
print("DUPE")
t.color_bg = random_color(search)
continue
return t.color_bg It appears to be working, as it prints "DUPE" many times and eventually returns.
However I am still ending up with 100 dupes out of 145 colors.
Very new to python/pygame so I must be missing something but can't see it, thanks.