Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_500x500_rgb_cosmic_explosion.py
- import tkinter as tk
- import random
- from PIL import Image, ImageTk, ImageFilter, ImageDraw
- ww = 500
- hh = 500
- cx = ww // 2
- cy = ww // 2
- p = 60
- root = tk.Tk()
- root.title("# tk_500x500_rgb_cosmic_explosion.py")
- root.geometry("%dx%d+%d+%d" %(ww, hh, 10, 10))
- canvas = tk.Canvas(root, width=ww, height=hh)
- canvas.pack()
- colors = []
- t = [z for z in range(0, 256, 15)]
- for r in t:
- for g in t:
- for b in t:
- colors += [(r, g, b, 255)]
- Lc = len(colors)
- def crop_center(img):
- w, h = img.size
- target_w, target_h = ww + 2, hh + 2
- left = (w - target_w) // 2
- top = (h - target_h) // 2
- right = left + target_w
- bottom = top + target_h
- return img.crop((left, top, right, bottom))
- alpha = 255 / 40
- black_image = Image.new('RGBA', (ww+p, hh+p), (0, 0, 0))
- def zoom():
- global image_a, image_b
- for i in range(1, 45):
- image_a = crop_center(image_a)
- image_a = image_a.resize((ww+p, hh+p), Image.BICUBIC)
- image_a = image_a.filter(ImageFilter.GaussianBlur(1.0))
- image_a = image_a.point(lambda x: x // 15 * 15)
- img = Image.blend(image_a.convert("RGBA"), black_image, max(0, i - 30) * 0.05)
- plot(img)
- image_a, image_b = image_b, generate_new_image()
- def generate_new_image():
- global idx
- size = 8
- buffer = 0
- for blur in (400, 400, 400, 400):
- img = Image.new("RGBA", (size, size))
- pixels = img.load()
- for y in range(size):
- for x in range(size):
- color = colors.pop(idx**3)
- idx = (idx + 1) % 16
- pixels[x, y] = color
- colors.append(color)
- img = img.resize((ww+p, hh+p))
- size *= 2
- return img
- def plot(buffer):
- rgb_image = buffer.convert('RGB')
- photo = ImageTk.PhotoImage(rgb_image)
- canvas.create_image(cx, cy, anchor=tk.CENTER, image=photo)
- canvas.image = photo
- canvas.update()
- t=50
- mask = Image.new('L', (ww+p, hh+p), 0)
- draw = ImageDraw.Draw(mask)
- for i in range(0, min(ww+p, hh+p) // 2, 10):
- draw.rectangle([i, i, ww+p - i, hh+p - i], fill=i*255//((min(ww+p, hh+p) // 2)+1))
- mask_size = (ww+p, hh+p)
- idx = 0
- image_a, image_b = [generate_new_image() for i in '..']
- while True:
- zoom()
- idx += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement