Advertisement
here2share

# Tk_grainy_rgb_scroll.py

Mar 7th, 2023
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # Tk_grainy_rgb_scroll.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import math
  6. import random
  7.  
  8. ww = 600
  9. hh = 600
  10.  
  11. def draw():
  12.     image.putdata(rgb)
  13.     photo = ImageTk.PhotoImage(image)
  14.     canvas.create_image(0,0,image=photo,anchor=NW)
  15.     canvas.update()
  16.    
  17. root = Tk()
  18. root.title("Tk_grainy_rgb_scroll")
  19. root.geometry("%dx%d+0+0"%(ww,hh))
  20.    
  21. canvas = Canvas(root, width=ww, height=hh)
  22. canvas.pack()
  23.  
  24. image = Image.new("RGB", (ww,hh), (255,255,255))
  25.  
  26. zzz = [i for i in range(255)]
  27. zzz = zzz[1:-1] + zzz[::-1]
  28. L = len(zzz)
  29.  
  30. rgb = [(128,128,128)]*(ww*hh)
  31. ref = rgb[:ww*2]
  32.  
  33. while 1:
  34.     buf = []
  35.     iii = 1
  36.     while len(buf) < ww:
  37.         r = g = b = 0
  38.         for i in [iii-1,iii,iii+1]:
  39.             r += ref[i][0]
  40.             g += ref[i][1]
  41.             b += ref[i][2]
  42.         ttt = []
  43.         for t in (r,g,b):
  44.             t = t//3
  45.             t += random.randint(-t//15,10)
  46.             ttt.append(t)
  47.         buf += [tuple(ttt)]
  48.         iii += 1
  49.     ref = buf * 2
  50.     ref = [ref[-1]] + ref
  51.     rgb.extend(buf[:ww])
  52.     rgb = rgb[-ww*hh:]
  53.     draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement