Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_color_plume.py almost like tk_blurred_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_color_plume")
- canvas = tk.Canvas(root, width=WW, height=HH, bg='black')
- root.geometry("%dx%d+10+10" % (WW, HH))
- canvas.pack()
- scale_factor = 2.1
- number_of_points = 10
- tag_id = {}
- points = []
- def capture_canvas():
- image = Image.new("RGBA", (WW, HH), (0, 0, 0, 0))
- draw = ImageDraw.Draw(image)
- for item in canvas.find_all():
- item_type = canvas.type(item)
- coords = canvas.coords(item)
- if item_type == "polygon":
- color = canvas.itemcget(item, "fill")
- draw.polygon(coords, fill=color)
- return image
- def make_polygon(args):
- r0, g0, b0, points = args
- tag_id[i] = canvas.create_polygon(points, fill="#{:02x}{:02x}{:02x}".format(r0, g0, b0), smooth=True)
- def blob():
- del points[:]
- r0, g0, b0 = [random.randint(0, 255) for _ in range(3)]
- for j in range(number_of_points):
- angle = 2 * math.pi * j / number_of_points
- r = random.uniform(1, 0.05)
- a = angle * random.uniform(0.95, 1)
- x = WC + r * math.cos(a)
- y = HC + r * math.sin(a)
- points.extend((x, y))
- return r0, g0, b0, points
- def plot():
- for _ in range(3):
- for j in tag_ids:
- try:
- x1, y1, x2, y2 = canvas.bbox(tag_id[j])
- center_x = (x1 + x2) / 2
- center_y = (y1 + y2) / 2
- new_width = (x2 - x1) * scale_factor
- new_height = (y2 - y1) * scale_factor
- delta_x = (new_width - (x2 - x1)) / 2
- delta_y = (new_height - (y2 - y1)) / 2
- canvas.scale(tag_id[j], center_x, center_y, scale_factor, scale_factor)
- except:
- tag_ids.remove(j)
- canvas.delete('img')
- img = capture_canvas()
- img = img.filter(ImageFilter.GaussianBlur(radius=50))
- canvas.image = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor=tk.NW, image=canvas.image, tags=('img'))
- canvas.update()
- i = 0
- tag_ids = [i]
- while 1:
- make_polygon(blob())
- plot()
- i += 1
- tag_ids += [i]
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement