here2share

# tk_rgba_color_wheel.py

Nov 3rd, 2025
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # tk_rgba_color_wheel.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk
  5. import math, colorsys
  6.  
  7. size = 250
  8. radius = 100
  9. center = (size // 2, size // 2)
  10. image = Image.new("RGBA", (size, size), (0, 0, 0, 0))
  11. pixels = image.load()
  12.  
  13. for y in range(size):
  14.     for x in range(size):
  15.         dx = x - center[0]
  16.         dy = y - center[1]
  17.         distance = math.hypot(dx, dy)
  18.         if distance <= radius:
  19.             angle = math.atan2(dy, dx)
  20.             hue = (angle + math.pi) / (2 * math.pi)
  21.             r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1, 1)]
  22.             alpha = int((1 - distance / radius) * 255)
  23.             pixels[x, y] = (r, g, b, alpha)
  24.  
  25. root = tk.Tk()
  26. root.title("tk RGBA Color Wheel")
  27.  
  28. tk_image = ImageTk.PhotoImage(image)
  29. label = tk.Label(root, image=tk_image)
  30. label.pack()
  31.  
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment