# HG changeset patch # User Paul Boddie # Date 1443894793 -7200 # Node ID 7437f3302bc870204ea87eecb2c05000c9c4b9b4 # Parent baa08ae98f2e88bd6a5d30e5980b768a0b0b5bb3 Experiment with different complementary pairs when reducing contributions. diff -r baa08ae98f2e -r 7437f3302bc8 optimiser.py --- a/optimiser.py Sat Oct 03 19:08:11 2015 +0200 +++ b/optimiser.py Sat Oct 03 19:53:13 2015 +0200 @@ -47,13 +47,35 @@ return rgb, restore(invert(scale(rgb))) def balance(d): + + # Find the dominant complementary pair. + + d.sort(reverse=True) + found = set() + for f, value in d: + value, complement = complements(value) + if value in found or complement in found: + found = [value, complement] + break + else: + found.add(value) + + # Remove the dominant primary (or black) from the list of colours. + + colours = [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)] + if found[0] in colours: + colours.remove(found[0]) + else: + colours.remove(found[1]) + d = dict([(value, f) for f, value in d]) - for primary, secondary in map(complements, [(255, 0, 0), (0, 255, 0), (0, 0, 255)]): + + for primary, secondary in map(complements, colours): common = min(d[primary], d[secondary]) d[primary] -= common d[secondary] -= common - d[(0, 0, 0)] += common - d[(255, 255, 255)] += common + d[found[0]] += common + d[found[1]] += common return [(f, value) for value, f in d.items()] def combine(d):