Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_rgb_whirlpool.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- ww = 250
- hh = 250
- root = tk.Tk()
- root.title("tk_rgb_whirlpool")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
- canvas.pack()
- cx, cy = ww//2, hh//2
- img = Image.new('RGB', (ww, hh), "white")
- rgb = []
- def create_rgb():
- t = list(range(0, 256, 50))
- rrr = t[:]
- ggg = t[:]
- bbb = t[:]
- r = g = b = 0
- while 1:
- for r in rrr:
- for g in ggg:
- for b in bbb:
- if (r,g,b) not in rgb:
- rgb.append((r,g,b))
- else:
- return
- if bbb.index(b) == len(bbb) - 1:
- bbb = bbb[::-1]
- if ggg.index(g) == len(ggg) - 1:
- ggg = ggg[::-1]
- rrr = rrr[::-1]
- create_rgb()
- L = len(rgb)
- cXY = []
- for y in range(hh):
- for x in range(ww):
- distance = ((cx-x)**2+(cy-y)**2)**0.5
- xy2 = math.atan2(x-cx,y-cy)
- cXY.append(((int(distance), xy2),x,y))
- cXY.sort()
- cXY = [(x,y) for z,x,y in cXY]
- LXY = len(cXY)
- j = 0
- while True:
- for i in range(LXY):
- x, y = cXY[i]
- img.putpixel((x, y), rgb[i%L])
- t = rgb.pop(0)
- rgb.insert(-j, t)
- j = (j+1)%10
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Add Comment
Please, Sign In to add comment