Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Psychedelic_Gradient_Circle.py
- import tkinter as tk
- from PIL import Image, ImageTk
- import math
- import time
- w, h = 300, 300
- cx, cy = w // 2, h // 2
- root = tk.Tk()
- canvas = tk.Canvas(root, width=w, height=h)
- canvas.pack()
- img = Image.new("RGB", (w, h))
- pixels = img.load()
- while 1:
- t = time.time()
- for y in range(h):
- for x in range(w):
- dx = x - cx
- dy = y - cy
- angle = math.atan2(dy, dx)
- dist = math.hypot(dx, dy)
- r = int((math.sin(dist / 10 + angle + t) * 127 + 128))
- g = int((math.cos(dist / 10 - angle + t) * 127 + 128))
- b = int((math.sin(dist / 15 + t) * 127 + 128))
- pixels[x, y] = (r & 255, g & 255, b & 255)
- tk_img = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=tk.NW, image=tk_img)
- root.update_idletasks()
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment