PageRenderTime 207ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/original/Compost.app/Contents/Resources/compost.py

https://github.com/aleray/datateb
Python | 100 lines | 68 code | 11 blank | 21 comment | 10 complexity | 68eb1812dda32d116365dc0c59368ce3 MD5 | raw file
Possible License(s): GPL-3.0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os, sys
  4. import time
  5. from PIL import Image
  6. from life import *
  7. import random
  8. import glob
  9. import EasyDialogs
  10. def bla(p, color):
  11. for i in range(len(list(p))):
  12. if i % 2:
  13. y = list(p)[i]
  14. else:
  15. x = list(p)[i]
  16. try:
  17. actualPix = pix[x,y]
  18. if color=="r":
  19. pix[x, y] = (255, actualPix[1], actualPix[2])
  20. if color=="g":
  21. pix[x, y] = (actualPix[0], 255, actualPix[2])
  22. if color=="b":
  23. pix[x, y] = (actualPix[0], actualPix[1], 255)
  24. pixCopy[x, y] = (0, 0, 0)
  25. except:
  26. print "negatif"
  27. return 0
  28. #snd = "/Volumes/STOCK/Users/aleray/Travaux/PZI/not_from_scratch/sounds/3370__heatfuse__mosquito.mp3"
  29. snd = "/Volumes/STOCK/Users/aleray/Travaux/PZI/not_from_scratch/sounds/piezorw1.wav"
  30. os.system("mplayer -loop 1000 %s &" % snd)
  31. meter = EasyDialogs.ProgressBar('Generating Life...',
  32. maxval=100,
  33. label='Starting',
  34. )
  35. for i in xrange(1, 101):
  36. phase = '%d %% Completed' % i
  37. print phase
  38. meter.label(phase)
  39. meter.inc()
  40. time.sleep(0.01)
  41. print 'Done with loop'
  42. time.sleep(1)
  43. del meter
  44. print 'The dialog should be gone now'
  45. # thePatterns=glob.glob('patterns/*.txt')
  46. # thePatterns+=glob.glob('patterns/*.lif')
  47. # print thePatterns
  48. im = Image.open(sys.argv[1])
  49. x, y = im.size
  50. pix = im.load()
  51. #
  52. f=open('/Volumes/STOCK/Users/aleray/Travaux/PZI/not_from_scratch/scripts_recycle/patterns/pattern_01.txt', 'r')
  53. p1 = pattern(f.read())
  54. f.close()
  55. p1 = p1 (random.randint(50,x-50),random.randint(50, y-50))
  56. f=open('/Volumes/STOCK/Users/aleray/Travaux/PZI/not_from_scratch/scripts_recycle/patterns/pattern_02.txt', 'r')
  57. p2 = pattern(f.read())
  58. f.close()
  59. p2 = p2 (random.randint(50,x-50),random.randint(50, y-50))
  60. f=open('/Volumes/STOCK/Users/aleray/Travaux/PZI/not_from_scratch/scripts_recycle/patterns/pattern_03.txt', 'r')
  61. p3 = pattern(f.read())
  62. f.close()
  63. p3 = p3 (random.randint(50,x-50),random.randint(50, y-50))
  64. #
  65. # #old = p
  66. #
  67. # # p4=[]
  68. # # for i in range(50):
  69. # # p4.append(random.randint(1,300))
  70. #
  71. # # p4
  72. # # p4 = p4 (100,100)
  73. #
  74. for a in range(1000):
  75. imCopy = im.copy()
  76. pixCopy = imCopy.load()
  77. #
  78. bla(p1, "r")
  79. p1 = p1.evolve(1)
  80. bla(p2, "g")
  81. p2 = p2.evolve(1)
  82. bla(p3, "b")
  83. p3 = p3.evolve(1)
  84. # if a % 10 == 0:
  85. # imCopy.save("nature_composted_%s.jpg" % (a))
  86. if a % 10 == 0:
  87. imCopy.save("/Users/aleray/Recycled/Compost/composted.jpg")
  88. #
  89. os.system("killall mplayer")