here2share

# Psychedelic_Gradient_Circle.py

Oct 6th, 2025
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # Psychedelic_Gradient_Circle.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk
  5. import math
  6. import time
  7.  
  8. w, h = 300, 300
  9. cx, cy = w // 2, h // 2
  10.  
  11. root = tk.Tk()
  12. canvas = tk.Canvas(root, width=w, height=h)
  13. canvas.pack()
  14.  
  15. img = Image.new("RGB", (w, h))
  16. pixels = img.load()
  17.  
  18. while 1:
  19.     t = time.time()
  20.  
  21.     for y in range(h):
  22.         for x in range(w):
  23.             dx = x - cx
  24.             dy = y - cy
  25.             angle = math.atan2(dy, dx)
  26.             dist = math.hypot(dx, dy)
  27.  
  28.             r = int((math.sin(dist / 10 + angle + t) * 127 + 128))
  29.             g = int((math.cos(dist / 10 - angle + t) * 127 + 128))
  30.             b = int((math.sin(dist / 15 + t) * 127 + 128))
  31.  
  32.             pixels[x, y] = (r & 255, g & 255, b & 255)
  33.  
  34.     tk_img = ImageTk.PhotoImage(img)
  35.     canvas.create_image(0, 0, anchor=tk.NW, image=tk_img)
  36.     root.update_idletasks()
  37.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment