PaletteOptimiser

Changeset

43:904ff97afe31
2015-10-04 Paul Boddie raw files shortlog changelog graph Limit colour exchange to those below a certain frequency threshold.
optimiser.py (file)
     1.1 --- a/optimiser.py	Sun Oct 04 18:07:00 2015 +0200
     1.2 +++ b/optimiser.py	Sun Oct 04 19:25:49 2015 +0200
     1.3 @@ -171,7 +171,7 @@
     1.4                  else:
     1.5                      c[value] += f
     1.6  
     1.7 -        c = [(n, value) for value, n in c.items()]
     1.8 +        c = [(n/width, value) for value, n in c.items()]
     1.9          c.sort(reverse=True)
    1.10          colours.append(c)
    1.11  
    1.12 @@ -191,9 +191,11 @@
    1.13          if least:
    1.14              switched = []
    1.15              for j in 1, 2:
    1.16 -                i = randrange(2, len(c))
    1.17 -                switched.append(c[i])
    1.18 -                del c[i]
    1.19 +                i = randrange(0, 4)
    1.20 +                n, value = c[i]
    1.21 +                if n < 0.1:
    1.22 +                    switched.append(c[i])
    1.23 +                    del c[i]
    1.24              c += switched
    1.25              most = [value for n, value in c[:4]]
    1.26              least = [value for n, value in c[4:]]