Advertisement
here2share

# Tk_RGB_random_scroll.py

Nov 8th, 2022
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # Tk_RGB_random_scroll.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import sin, cos, radians
  6. import random
  7.  
  8. ri = random.randint
  9.  
  10. ww = 600
  11. hh = 600
  12.  
  13. root = Tk()
  14. root.title("Tk_RGB_random_scroll")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16.    
  17. canvas = Canvas(root, width=ww, height=hh)
  18. canvas.pack()
  19.  
  20. image = Image.new("RGB", (ww,hh), (255,255,255))
  21.  
  22. scan = [[128,128,128] for i in '.'*ww]
  23.  
  24. def rgb2hex(r,g,b):
  25.     return '#%02X%02X%02X'%(r,g,b)
  26.  
  27. def draw():
  28.     image.putdata(rgb)
  29.     photo = ImageTk.PhotoImage(image)
  30.     canvas.create_image(0,0,image=photo,anchor=NW)
  31.     canvas.update()
  32.  
  33. rgb = []
  34. def main():
  35.     global rgb
  36.     i = 0
  37.     while len(rgb) < ww*hh:
  38.         i = core(i)
  39.         draw()
  40.  
  41.     while 1:
  42.         rgb = rgb[ww:]
  43.         i = core(i)
  44.         draw()
  45.  
  46. peak = 60
  47. def core(i):
  48.     for j in range(ww):
  49.         p1 = scan[j-2]
  50.         p2 = scan[j-1]
  51.         p3 = scan[j]
  52.         color = []
  53.         for k in [0,1,2]:
  54.             t = int((p1[k]+p2[k]+p3[k])/3)
  55.             t += ri(-peak,peak)
  56.             if t < 0: t = 0
  57.             elif t > 255: t = 255
  58.             color += [t]
  59.         scan[j-1] = tuple(color)
  60.     rgb.extend(scan)
  61.     return i
  62.    
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement