TheCDC

Untitled

Feb 28th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import itertools
  2. import pprint
  3.  
  4. pp=pprint.PrettyPrinter()
  5. # things to permute
  6. def get_permutations(l,n):
  7.     """Self-explanatory"""
  8.     return list(set(itertools.permutations(l,n)))
  9.  
  10.  
  11. def get_color_families(step):
  12.     """
  13.     Don't use this. Too many similar colors.
  14.     """
  15.     values = tuple([i - 1*(i>=256) for i in range(0,257,step)])
  16.     out = []
  17.     for a in values:
  18.         for b in values:
  19.             for c in values:
  20.                 v = (a,b,c)
  21.                 if 255 in v:
  22.                     out.append(v)
  23.     return tuple(set(out))
  24.     # return [(0,((i//256)%256)//step,i%256) for i in range(0,256**3,step)]
  25.  
  26. # pp.pprint(get_color_families(64))
  27.  
  28. with open("rbg_templates.txt") as f:
  29.     colorCombs = [[int(v) for v in i.split(',')] for i in f.read().split('\n') ]
  30.     # example contents:
  31. # 255,0,0
  32. # 255,64,0
  33. # 255,64,64
  34. # 255,127,0
  35. # 255,127,64
  36. # 255,127,127
  37. # 255,192,0
  38. # 255,255,0
  39. # 255,255,127
  40. # 255,255,255
  41. # notice that these are the digits of a base-256 number as it is incremented
  42. # BRB automating that
  43.  
  44. # even those could be generated algorithmically
  45.  
  46. N = 3
  47. outList = []
  48.  
  49. # interleave the color families in order to keep the visuals interesting
  50. interleaved = colorCombs[:len(colorCombs)//2] + colorCombs[len(colorCombs)//2:][::-1]
  51.  
  52. # print(interleaved)
  53.  
  54. for i in interleaved:
  55.     outList += get_permutations(i,N)[::-1]
  56.  
  57. outstr = "const int numColors = {number};\nint niceColors[][3] = {{\n\t {colors} \n}};".format(
  58.     number=len(outList),
  59.     colors=",\n\t".join([str(i).replace("(","{").replace(")","}") for i in outList])
  60.     )
  61.  
  62. print(outstr)
  63. with open("permutations.txt",'w') as f:
  64.     f.write(outstr)
Advertisement
Add Comment
Please, Sign In to add comment