Advertisement
here2share

# Tk_rgb_transition.py

Mar 30th, 2022
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # Tk_rgb_transition.py
  2.  
  3. from tkinter import *
  4. import time
  5. from PIL import Image, ImageTk
  6. from random import shuffle as rs, randint as ri
  7.  
  8. tx =  time.time
  9. ww = 600
  10. hh = 600
  11.  
  12. root = Tk()
  13. root.title("Tk_rgb_transition")
  14. root.geometry("%dx%d+-6+-2"%(ww,hh))
  15. canvas = Canvas(width=ww, height=hh)
  16. canvas.pack()
  17.  
  18. def motion(event):
  19.     mouse_pos.append((event.x, event.y))
  20. root.bind('<B1-Motion>', motion)
  21.  
  22. rgb = []
  23. screen = []
  24. xy = {}
  25. w = 255.0/ww
  26. h = 255.0/hh
  27.  
  28. ttt = [i for i in range(0,255)]
  29. ttt = ttt[:-1]+ttt[::-1]
  30. ttt.pop()
  31. L = len(ttt)
  32.  
  33. for j in range(0,hh):
  34.     for i in range(0,ww):
  35.         xy[i,j] = len(rgb)
  36.         rgb += [(int(j*h),int(i*w),min(i,j))]
  37.         screen += [(i,j)]
  38.        
  39. rgb_float = rgb[:]
  40.  
  41. mouse_pos = []
  42. image = Image.new("RGB", (ww,hh))
  43.  
  44. def draw():
  45.     image.putdata(rgb)
  46.     photo = ImageTk.PhotoImage(image)
  47.     canvas.create_image(0,0,image=photo,anchor=NW)
  48.     canvas.update()
  49.  
  50. incr = [round(i*0.01,2) for i in range(1,101)]
  51. incr = incr[:-1]+incr[::-1]
  52. incr.pop()
  53. incr2 = incr[:]
  54.  
  55. transition = range(3,70000,111)
  56. L2 = len(transition)
  57.  
  58. while 1:
  59.     # rs(screen)
  60.     for i,j in screen:                 
  61.         t = xy[i,j]
  62.         pa = []
  63.         pb = []
  64.         for k,v in enumerate(rgb_float[t]):
  65.             v2 = transition[(t**(k*3+7))%L2]
  66.             p = (v+v2)%L
  67.             pa += [p]
  68.             pb += [ttt[int(p)%L]]
  69.         rgb_float[t] = pa
  70.         rgb[t] = tuple(pb)
  71.     draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement