Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_extra_colorful_zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- import math
- import random
- WW, HH = 600, 600
- WC, HC = WW // 2, HH // 2
- root = tk.Tk()
- root.title("# tk_extra_colorful_zoom")
- canvas = tk.Canvas(root, width=WW, height=HH)
- root.geometry("%dx%d+10+10" % (WW, HH))
- canvas.pack()
- image = Image.new("RGB", (WW, HH), 'black')
- radius = min(WC, HC) // 2
- number_of_points = 12
- def blob(image):
- pixels = image.load()
- r0, g0, b0 = [random.randint(0, 255) for _ in '...']
- points = []
- for j in range(number_of_points):
- angle = 2 * math.pi * j / number_of_points
- r = radius * random.uniform(0.01, 0.1)
- a = angle * random.uniform(0.95, 1)
- x = HC + r * math.cos(a) + 7
- y = WC + r * math.sin(a) + 7
- points.append((x, y))
- draw = ImageDraw.Draw(image)
- draw.polygon(points, fill=(r0, g0, b0))
- return image
- zoom = 50
- XY = []
- for x in range(-1, 4):
- for y in range(-1, 4):
- XY += [(zoom + x, zoom + y, WW-zoom + x, HH-zoom + y)]
- XY *= 10
- def create_blurred_circle(size, center, radius, blur_radius):
- theVoid = Image.new("RGBA", size, (0, 0, 0, 0))
- draw = ImageDraw.Draw(theVoid)
- draw.ellipse((center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius), fill=(0, 0, 0, 255))
- return theVoid.filter(ImageFilter.GaussianBlur(blur_radius))
- theVoid = create_blurred_circle((WW, HH), (WC, HC), 24, 14)
- canvas_image = canvas.create_image(0, 0, anchor=tk.NW)
- while 1:
- random.shuffle(XY)
- for x1, y1, x2, y2 in XY:
- image = image.crop((x1, y1, x2, y2))
- image = image.resize((WW, HH))
- image2 = blob(image)
- image2 = Image.alpha_composite(image2.convert("RGBA"), theVoid).convert("RGB")
- gradient_photo = ImageTk.PhotoImage(image2)
- canvas.itemconfig(canvas_image, image=gradient_photo)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement