# HG changeset patch # User Paul Boddie # Date 1444344059 -7200 # Node ID 4d2f52b71f3c4df24177139ddb70520fed8db762 # Parent aa75aca1ebd7832775caaf35e6725b2960172142 Removed the colour cache: entries seemed to acquire rounded probabilities. diff -r aa75aca1ebd7 -r 4d2f52b71f3c optimiser.py --- a/optimiser.py Fri Oct 09 00:34:32 2015 +0200 +++ b/optimiser.py Fri Oct 09 00:40:59 2015 +0200 @@ -62,39 +62,33 @@ # Colour distribution functions. -cache = {} - def combination(rgb): "Return the colour distribution for 'rgb'." - if not cache.has_key(rgb): - - # Get the colour with components scaled from 0 to 1, plus the inverted - # component values. + # Get the colour with components scaled from 0 to 1, plus the inverted + # component values. - rgb = extra(scale(rgb)) - rgbi = invert(rgb) - pairs = zip(rgbi, rgb) + rgb = extra(scale(rgb)) + rgbi = invert(rgb) + pairs = zip(rgbi, rgb) - # For each corner of the colour cube (primary and secondary colours plus - # black and white), calculate the corner value's contribution to the - # input colour. + # For each corner of the colour cube (primary and secondary colours plus + # black and white), calculate the corner value's contribution to the + # input colour. - d = [] - for corner in corners: - rs, gs, bs = scale(corner) - - # Obtain inverted channel values where corner channels are low; - # obtain original channel values where corner channels are high. + d = [] + for corner in corners: + rs, gs, bs = scale(corner) - d.append((pairs[0][int(rs)] * pairs[1][int(gs)] * pairs[2][int(bs)], corner)) - - # Balance the corner contributions. + # Obtain inverted channel values where corner channels are low; + # obtain original channel values where corner channels are high. - cache[rgb] = balance(d) + d.append((pairs[0][int(rs)] * pairs[1][int(gs)] * pairs[2][int(bs)], corner)) - return cache[rgb] + # Balance the corner contributions. + + return balance(d) def complements(rgb):