here2share

# tk_400x400_putpixel_max_speed_test.py

May 23rd, 2023 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # tk_400x400_putpixel_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_putpixel_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. cx, cy = ww//2, hh//2
  17.  
  18. img = Image.new('RGB', (ww, hh), (128, 128, 128))
  19.  
  20. rgb = []
  21. def create_rgb():
  22.     t = list(range(0, 256, 15))
  23.     rrr = t[:]
  24.     ggg = t[:]
  25.     bbb = t[:]
  26.     r = g = b = 0
  27.     while 1:
  28.         for r in rrr:
  29.             for g in ggg:
  30.                 for b in bbb:
  31.                     if (r,g,b) not in rgb:
  32.                         rgb.append((r,g,b))
  33.                     else:
  34.                         return
  35.                 if bbb.index(b) == len(bbb) - 1:
  36.                     bbb = bbb[::-1]
  37.             if ggg.index(g) == len(ggg) - 1:
  38.                 ggg = ggg[::-1]
  39.         rrr = rrr[::-1]
  40. create_rgb()
  41.  
  42. while True:
  43.     pixels = rgb[:]
  44.     for pixel in pixels:
  45.         for x in range(0, ww):     
  46.             for y in range(0, hh):
  47.                 img.putpixel((x, y), pixel)
  48.         tkimg = ImageTk.PhotoImage(img)
  49.         canvas.create_image((cx, cy), image=tkimg)
  50.         canvas.update()
  51.  
Add Comment
Please, Sign In to add comment