Advertisement
here2share

# Tk_Pastel_Pixels.py

Dec 6th, 2019
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # Tk_Pastel_Pixels.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6.  
  7. root = Tk()
  8. root.title("Pastel Pixels")
  9. width = 200
  10. height = 200
  11. root.geometry("%dx%d"%(width, height))
  12. w = Canvas(root, width=width, height=height)
  13. w.pack()
  14.  
  15.  
  16. def rnd():
  17.     return [random.randint(0, 255) for z in '...']
  18.  
  19. def data_process(y):
  20.     for x in xrange(width):
  21.         m = random.randint(3, 12)
  22.         try:
  23.             xRGB = xy[((y-1)*width)+x]
  24.         except:
  25.             xRGB = rnd()
  26.         try:
  27.             yRGB = xy[(y*width)+(x-1)]
  28.         except:
  29.             yRGB = rnd()
  30.         rgb = tuple([int((((xRGB[z]+yRGB[z])/25*25*m)+rnd()[0])/(m*2+1)*1.054) for z in xrange(3)])
  31.         xy.append(rgb)
  32. #
  33. img = Image.new( 'RGB', (width,height))
  34. while 1:
  35.     xy = []
  36.     for y in xrange(height):
  37.         data_process(y)
  38.     # print min(xy), max(xy)
  39.     img.putdata(xy)
  40.     imgTk = ImageTk.PhotoImage(img)
  41.     #time.sleep(0.02)
  42.     w.create_image(0, 0, anchor=NW, image=imgTk)
  43.     root.update()
  44. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement