MoSBanapple

Untitled

Nov 24th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import sys
  2. import os.path
  3. import numpy as np
  4. import PIL
  5. from random import randint
  6. try:
  7. import Image
  8. except ImportError:
  9. from PIL import Image
  10.  
  11.  
  12. def readFile(nameoffile):
  13. list = []
  14. with open(nameoffile, 'r') as f:
  15. for line in f:
  16.  
  17. list.append(line.rstrip())
  18. return list
  19.  
  20. def randomTeam(characters):
  21. team = []
  22. while len(team) < 3:
  23. num = randint(0,len(characters)-1)
  24. chosen = characters[num]
  25. if chosen[0] == 'm':
  26. continue
  27. overlap = False
  28. for iter in team:
  29. if chosen[0] == iter[0]:
  30. overlap = True
  31. if not overlap:
  32. team.append(chosen)
  33.  
  34. while len(team) < 4:
  35. master = characters[randint(0,len(characters)-1)]
  36. if master[0] == 'm':
  37. team.append(master)
  38. return team
  39.  
  40. list = readFile('characters.txt')
  41. counts = {}
  42. for char in list:
  43. counts[char] = 0
  44. for x in range(10000):
  45. team = randomTeam(list)
  46. for char in team:
  47. counts[char] += 1
  48.  
  49. output = open('counts.txt', 'w')
  50. output.write("hello")
  51. for char in list:
  52. to_add = char + ": " + str(counts[char]) + '\n'
  53. output.write(to_add)
  54.  
  55. '''
  56. while ('b ed.jpg' not in list_im):
  57. list_im = randomTeam(list)
  58. '''
  59. """
  60. imgs = [ PIL.Image.open(i) for i in list_im ]
  61. # pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
  62. min_shape = sorted( [(np.sum(i.size), i.size ) for i in imgs])[0][1]
  63. imgs_comb = np.hstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
  64.  
  65. # save that beautiful picture
  66. imgs_comb = PIL.Image.fromarray( imgs_comb)
  67. imgs_comb.save( 'Trifecta.jpg' )
  68.  
  69. # for a vertical stacking it is simple: use vstack
  70. """
  71.  
  72. """
  73. imgs_comb = np.vstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
  74. imgs_comb = PIL.Image.fromarray( imgs_comb)
  75. imgs_comb.save( 'Trifecta_vertical.jpg' )
  76. """
Advertisement
Add Comment
Please, Sign In to add comment