Advertisement
here2share

# Tkinter_pixel_pooling.py -- ZZZ

Jun 10th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. # pixel_pooling.py   --   from generic_multiprocessing.py as a graphic speed test
  2.  
  3. from multiprocessing.pool import ThreadPool
  4. import multiprocessing
  5. import time
  6. import random
  7.  
  8. wi = 120
  9. he = 80
  10. from Tkinter import *
  11. root = Tk()
  12. root.geometry("%sx%s" % (wi,he))
  13. root.title("Pixel Pooling")
  14. w = Canvas(root, bg="white")
  15. w.pack()
  16.  
  17. rgb = {}
  18. fff = {}
  19. def p(z):
  20.     return random.randrange(90,165)+z/1.8
  21.    
  22. for z in range(he):
  23.     rgb[z] = {'r':p(z),'g':p(z),'b':p(z)}
  24.     fff[z] = {'r':1,'g':2,'b':3}
  25.  
  26. def draw_data(y):
  27.     rgbX = 'r g b'.split()
  28.     random.shuffle(rgbX)
  29.     for x in range(wi):
  30.         c = '#'
  31.         for z in rgbX:
  32.             if rgb[y][z] < 80 or rgb[y][z] > 175:
  33.                 fff[y][z] *= -1
  34.             rgb[y][z] += fff[y][z]
  35.             v = int(rgb[y][z])
  36.             c += '%02x' %(v)
  37.         w.create_line(x,y,x+1,y+1,fill=c,tags="tmp")
  38.    
  39.  
  40. pool = ThreadPool(120)
  41.  
  42. while 1:
  43.     w.delete("tmp")
  44.     pool.map(draw_data, range(he))
  45.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement