Advertisement
Peaser

Numberphile illegal_number sheetmaker

Aug 3rd, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. import binascii #Binary stuff
  2. from PIL import Image #Create image
  3.  
  4. from PIL import ImageFont  #Write text
  5. from PIL import ImageDraw  #Ditto
  6.  
  7. #WORK IN PROGRESS...
  8. #still very buggy
  9.  
  10. width, height = (1000, 500) #<--- Image dimensions, CUSTOMIZE THIS!
  11.  
  12. def avAll(object):
  13.     """LIST OF TUPLES(LEN=3)"""
  14.     a,b,c=[],[],[]
  15.     a.append([i[0] for i in object])
  16.     b.append([i[1] for i in object])
  17.     c.append([i[2] for i in object])
  18.     a = [sum(i)/len(i) for i in a]
  19.     b = [sum(i)/len(i) for i in b]
  20.     c = [sum(i)/len(i) for i in c]
  21.     return (a,b,c)
  22.  
  23. def binencode(object):
  24.     return bin(int(binascii.hexlify(object), 16)).replace('b','')
  25.  
  26. def chop(object,length):
  27.     return [object[i:i+length] for i in range(0, len(object), length)]
  28.  
  29. def recur2(object, n):
  30.     step = len(object)
  31.     b = []
  32.     for i in object:
  33.         for i2 in range(n):
  34.             b.append(i)
  35.     b.append((0,0,0))
  36.     return b
  37.  
  38. def comma(x):
  39.     if type(x) not in [int, long]:
  40.         raise TypeError("x must be a valid integer")
  41.     if x < 0:
  42.         return '-' + comma(-x)
  43.     f = ''
  44.     while x >= 1000:
  45.         x, r = divmod(x, 1000)
  46.         f = ",%03d%s" % (r, f)
  47.     return "%d%s" % (x, f)
  48.  
  49. def colfhex(value):
  50.     lv = len(value)
  51.     return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))
  52. try:
  53.     b = raw_input(">>>").upper()
  54.  
  55.     secret_number = comma(int(''.join([binencode(i) for i in b]), 2)) #large number.
  56.     hexy_bits = chop(str(hex(int(''.join([binencode(i) for i in b]), 2))[2:][:-1]), 6) #color hexes with remainder
  57.     color_pallet = [colfhex(_) for _ in chop(str(hex(int(''.join([binencode(i) for i in b]), 2))[2:][:-1]), 6)[:-1]] #<-what really matters
  58.     remainder = hexy_bits[-1:]
  59.     colordata = recur2(color_pallet, width/len(hexy_bits[:-1]))
  60.     print hexy_bits
  61.     img = Image.new('RGB', (width,height), "white")
  62.     img.putdata(colordata*height)
  63.     draw = ImageDraw.Draw(img)
  64.     font = ImageFont.truetype("arial.ttf", 50)
  65.     draw.text((0, 0),"+"+remainder[0],(255,255,255),font=font)
  66.     img.show()
  67.  
  68. except IndexError: print "Input too short! Must be greater than 6 characters."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement