# HG changeset patch # User Paul Boddie # Date 1443901687 -7200 # Node ID 03b740684b1f96b23d1c642df98b916c518bc520 # Parent 7437f3302bc870204ea87eecb2c05000c9c4b9b4 Changed the test for the most prominent pair to sum complement contributions. diff -r 7437f3302bc8 -r 03b740684b1f optimiser.py --- a/optimiser.py Sat Oct 03 19:53:13 2015 +0200 +++ b/optimiser.py Sat Oct 03 21:48:07 2015 +0200 @@ -50,15 +50,20 @@ # Find the dominant complementary pair. - d.sort(reverse=True) - found = set() + found = {} + for f, value in d: - value, complement = complements(value) - if value in found or complement in found: - found = [value, complement] - break + l = list(complements(value)) + l.sort() + t = tuple(l) + if not found.has_key(t): + found[t] = f else: - found.add(value) + found[t] += f + + pairs = [(f, t) for t, f in found.items()] + pairs.sort(reverse=True) + found = pairs[0][1] # Remove the dominant primary (or black) from the list of colours. @@ -210,12 +215,6 @@ most = [value for n, value in c[:4]] least = [value for n, value in c[4:]] - #if least: - # if (0, 0, 0) in least[:2]: - # replace((0, 0, 0), most) - # if (255, 255, 255) in least[:2]: - # replace((255, 255, 255), most) - for x in range(0, width): rgb = im.getpixel((x, y))