Advertisement
here2share

# tk_rgb_spiral_test.py

May 28th, 2023 (edited)
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. # tk_rgb_spiral_test.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw, ImageFilter
  5. import math
  6.  
  7. ww = 640
  8. hh = 640
  9.  
  10. root = tk.Tk()
  11. root.title("tk_rgb_spiral_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. img = Image.new('RGB', (ww, hh), "white")
  18.  
  19. rgb = [(255, 0, 0), (255, 127, 0), (255, 255, 0), (127, 255, 0), (0, 255, 0), (0, 255, 127), (0, 255, 255), (0, 127, 255),  (0, 0, 255)] * (ww*hh)
  20. rgb = rgb[:(ww*hh)]
  21. rgb.sort()
  22. L = len(rgb)
  23.  
  24. cXY = []
  25. for y in range(hh):
  26.     for x in range(ww):
  27.         distance = ((cx-x)**2+(cy-y)**2)**0.5
  28.         xy2 = math.atan2(x-cx,y-cy)
  29.         cXY.append(((int(distance), xy2),x,y))
  30. cXY.sort()
  31. cXY = [(x,y) for z,x,y in cXY]
  32. LXY = len(cXY)
  33.  
  34. while True:
  35.     for i in range(LXY):
  36.         x, y = cXY[i]
  37.         img.putpixel((x, y), rgb[i%L])
  38.  
  39.     a = rgb[::2]
  40.     b = rgb[1::2]
  41.     rgb = []
  42.     rgb.extend(a)
  43.     rgb.extend(b)
  44.    
  45.     tkimg = ImageTk.PhotoImage(img)
  46.     canvas.create_image((cx, cy), image=tkimg)
  47.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement