Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_intergalactic.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import math
- import random
- import io
- ww = 599
- hh = 599
- root = tk.Tk()
- root.title("tk_intergalactic")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = tk.Canvas(root, bg='white', width=ww, height=hh)
- canvas.pack()
- scale = 0
- zoom = 0.05
- cx, cy = ww//2, hh//2
- img = Image.new('RGB', (ww, hh), "white")
- pixels = []
- t = 100
- XY = [(x, y) for x in range(cx-t, cx+t) for y in range(cy-t, cy+t)]
- random.shuffle(XY)
- for y in range(hh):
- for x in range(ww):
- r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- pixels.append((r, g, b))
- img.putdata(pixels)
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- # calculate the blur radius to achieve 0.01% blur
- blur_radius = 0.0009 * min(img.size)
- rnd = 50
- # Zoom effect
- while True:
- for i in range(1000):
- x, y = XY.pop(0)
- XY.insert(-(10-(i%10)), (x, y))
- r, g, b = img.getpixel((x,y))
- r = max(0, min(255, r + random.randint(-rnd, rnd)))
- g = max(0, min(255, g + random.randint(-rnd, rnd)))
- b = max(0, min(255, b + random.randint(-rnd, rnd)))
- img.putpixel((x, y), (r, g, b))
- xt, yt = int(ww+scale), int(hh+scale)
- img = img.resize((xt, yt), resample=Image.LANCZOS)
- img = img.filter(ImageFilter.GaussianBlur(radius=blur_radius))
- # crop parameters to zoom into the center
- img = img.crop((scale/2, scale/2, xt-scale/2, yt-scale/2))
- scale += zoom
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement