Advertisement
here2share

# Tk_1200x680_Each_Pixel_A_Random_Color_Test_6.py

Apr 4th, 2021
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # Tk_1200x680_Each_Pixel_A_Random_Color_Test_6.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import multiprocessing as mp
  6. from random import choice as rnd
  7. import time
  8.  
  9. def oRGB(rgb): # pass
  10.     r,g,b = rgb
  11.     return "#%02x%02x%02x" % (r,g,b)
  12.  
  13. ww = 1200
  14. hh = 680
  15. root = Tk()
  16. root.title("Tk_1200x680_Each_Pixel_A_Random_Color_Test_5")
  17. root.geometry("%dx%d+0+0"%(ww,hh))
  18. canvas = Canvas(root, width=ww, height=hh)
  19. canvas.grid()
  20.  
  21. RGBs = []
  22. def z():
  23.     RGBs.append((r,g,b))
  24. r,g,b = 255,0,0
  25. for g in range(256):
  26.     z()
  27. for r in range(254, -1, -1):
  28.     z()
  29. for b in range(256):
  30.     z()
  31. for g in range(254, -1, -1):
  32.     z()
  33. for r in range(256):
  34.     z()
  35. for b in range(254, -1, -1):
  36.     z()
  37.  
  38. img = Image.new("RGB",(ww, hh))
  39.  
  40. def my_function():
  41.     result = []
  42.     for z in range(ww):
  43.         result += [rnd(RGBs)]
  44.     return result
  45.  
  46. def get_result(result):
  47.     pix.extend(result)
  48.  
  49. if __name__ == '__main__':
  50.     while 1:
  51.         pix = []
  52.         pool = mp.Pool(mp.cpu_count())
  53.         for i in range(0, hh):
  54.             pool.apply_async(my_function, args=(), callback=get_result)
  55.         pool.close()
  56.         pool.join()
  57.         img.putdata(pix)
  58.         imgTk = ImageTk.PhotoImage(img)
  59.         canvas.create_image(0, 0, anchor=NW, image=imgTk)
  60.         canvas.update()
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement