Advertisement
here2share

# Tk_Gradient_Scatter.py

Feb 28th, 2021
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # Tk_Gradient_Scatter.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import math
  7. import time
  8.  
  9. ww = 640
  10. hh = 640
  11. root = Tk()
  12. root.title("Tk Gradient Scatter")
  13. root.geometry("%dx%d+0+0"%(ww,hh))
  14. canvas = Canvas(root, width=ww, height=hh)
  15. canvas.grid()
  16.  
  17. RGBs = []
  18. def z():
  19.     RGBs.append((r,g,b))
  20. r,g,b = 255,0,0
  21. for g in range(256):
  22.     z()
  23. for r in range(254, -1, -1):
  24.     z()
  25. for b in range(256):
  26.     z()
  27. for g in range(254, -1, -1):
  28.     z()
  29. for r in range(256):
  30.     z()
  31. for b in range(254, -1, -1):
  32.     z()
  33.  
  34. Lc = len(RGBs)
  35.  
  36. img = Image.new("RGB",(ww,hh), "white")
  37.  
  38. while 1:
  39.     pix = []
  40.     inc = 0.002
  41.     yoff = 0
  42.     for x in range(ww):
  43.         xoff = 0
  44.         for y in range(hh):
  45.             rgb = int(random.uniform(xoff, yoff)*Lc)
  46.             # rgb = int((xoff+yoff)/2*Lc)
  47.             pix.append(RGBs[rgb%Lc])
  48.             xoff += inc
  49.         yoff += inc
  50.  
  51.     img.putdata(pix)
  52.     imgTk = ImageTk.PhotoImage(img)
  53.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  54.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement