here2share

# tk_400x400_putdata_max_speed_test.py

May 23rd, 2023
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. # tk_400x400_putdata_max_speed_test.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk
  5. import math
  6.  
  7. ww = 400
  8. hh = 400
  9.  
  10. root = tk.Tk()
  11. root.title("tk_400x400_putdata_max_speed_test")
  12. root.geometry("%dx%d+0+0"%(ww,hh))
  13. canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
  14. canvas.pack()
  15.  
  16. def draw():
  17.     img.putdata(art)
  18.     photo = ImageTk.PhotoImage(img)
  19.     canvas.create_image(0,0,image=photo,anchor='nw')
  20.     canvas.update()
  21.  
  22. rgb = []
  23. def create_rgb():
  24.     t = list(range(0, 256, 15))
  25.     rrr = t[:]
  26.     ggg = t[:]
  27.     bbb = t[:]
  28.     r = g = b = 0
  29.     while 1:
  30.         for r in rrr:
  31.             for g in ggg:
  32.                 for b in bbb:
  33.                     if (r,g,b) not in rgb:
  34.                         rgb.append((r,g,b))
  35.                     else:
  36.                         return
  37.                 if bbb.index(b) == len(bbb) - 1:
  38.                     bbb = bbb[::-1]
  39.             if ggg.index(g) == len(ggg) - 1:
  40.                 ggg = ggg[::-1]
  41.         rrr = rrr[::-1]
  42. create_rgb()
  43.  
  44. art = [(0, 0, 0)] * (ww * hh)
  45. art = art[:]
  46. img = Image.new('RGB', (ww, hh), (0, 0, 0))
  47.  
  48. i = 0
  49. xy = {}
  50. for x in range(0, ww):     
  51.     for y in range(0, hh):
  52.         xy[x,y] = i
  53.         i += 1
  54.  
  55. while True:
  56.     pixels = rgb[:]
  57.     for pixel in pixels:
  58.         for x in range(0, ww):     
  59.             for y in range(0, hh):
  60.                 art[xy[x, y]] = pixel
  61.         draw()
  62.  
Add Comment
Please, Sign In to add comment