Advertisement
here2share

# Tk_RGB_ani.py

Dec 25th, 2021
1,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # Tk_RGB_ani.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import math
  7. import time
  8.  
  9. ww = 270
  10. hh = 270
  11. root = Tk()
  12. root.title("Tk RGB")
  13. root.geometry("%dx%d+0+0"%(ww,hh))
  14. canvas = Canvas(root, width=ww, height=hh)
  15. canvas.grid()
  16.  
  17. img = Image.new("RGB",(ww,hh), "white")
  18.  
  19. cc = {}
  20. for x in range(ww):
  21.     for y in range(hh):
  22.         cc[x,y] = 0
  23.  
  24. xy = []
  25. x2 = 256.0/ww
  26. y2 = 256.0/hh
  27. for y in range(hh):
  28.     b = int(y*y2)
  29.     for x in range(ww):
  30.         a = int(x*x2)
  31.         c = cc[a,b]
  32.         xy += [(a,b,c)]
  33.         cc[a,b] = c+1
  34. 0
  35. animate = list(map(list, xy))
  36. while 1:
  37.     img.putdata(xy)
  38.     imgTk = ImageTk.PhotoImage(img)
  39.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  40.     root.update()
  41.     xy = []
  42.     for i,rgb in enumerate(animate):
  43.         ttt = []
  44.         for j,v in enumerate((7,9,11)):
  45.             t = rgb[j]-v
  46.             if t < -255:
  47.                 t = 255
  48.             ttt += [abs(t)]
  49.             animate[i][j] = t
  50.         xy += [tuple(ttt)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement