Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_rgb_spiral_test.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- ww = 640
- hh = 640
- root = tk.Tk()
- root.title("tk_rgb_spiral_test")
- 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 = [(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)
- rgb = rgb[:(ww*hh)]
- rgb.sort()
- 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)
- while True:
- for i in range(LXY):
- x, y = cXY[i]
- img.putpixel((x, y), rgb[i%L])
- a = rgb[::2]
- b = rgb[1::2]
- rgb = []
- rgb.extend(a)
- rgb.extend(b)
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement