Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_random_infinite_zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- import random
- import math
- ww = 300
- hh = 300
- root = tk.Tk()
- root.title("tk_random_infinite_zoom")
- 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")
- zoom = 1.9
- rnd = 10
- w2 = int(ww*0.25)
- h2 = int(hh*0.25)
- while 1:
- for y0 in range(w2, ww-w2, 2):
- for x0 in range(h2, hh-h2, 2):
- for (x, y) in ((x0, y0), (x0+1, y0), (x0, y0+1)):
- 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))
- # crop parameters to zoom into the center
- img = img.crop((zoom*3, zoom*3, ww-zoom*3, hh-zoom*3))
- img = img.resize((ww, hh), resample=Image.LANCZOS)
- tkimg = ImageTk.PhotoImage(img)
- canvas.create_image((cx, cy), image=tkimg)
- canvas.update()
- canvas.scale('all', cx, cy, zoom, zoom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement