Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_infinite_interpolation.py
- import random
- import tkinter as tk
- from PIL import Image,ImageTk
- root = tk.Tk()
- canvas = tk.Canvas(root, width=600, height=600)
- root.title("tk_infinite_interpolation.py")
- canvas.pack()
- pixels = [(200, 200, 200)] * 600 * 600
- rnd = 10
- NEW_SCALE_CONSTANT = [(0)] * 1200 * 1200
- new_scale = []
- def interpolate():
- global new_scale
- new_scale = NEW_SCALE_CONSTANT[:]
- for iii in range(600):
- for jjj in range(600):
- r, g, b = pixels[iii * 600 + jjj]
- i = iii * 2
- j = jjj * 2
- for i2, j2 in [(i,j),(i+1,j),(i,j+1),(i+1,j+1)]:
- rrr = min(255, max(0, r + random.randint(-rnd, rnd)))
- ggg = min(255, max(0, g + random.randint(-rnd, rnd)))
- bbb = min(255, max(0, b + random.randint(-rnd, rnd)))
- new_scale[i2 * 1200 + j2] = (rrr, ggg, bbb)
- img = Image.new("RGB", (1200, 1200))
- while 1:
- interpolate()
- # Create a PIL.Image object from the pixel data
- img.putdata(new_scale)
- zoom = 10
- current_size = 600
- while current_size < 1200:
- canvas.delete(tk.ALL)
- sz = int(current_size)
- scaled_image = img.resize((sz, sz), Image.ANTIALIAS)
- scaled_image = ImageTk.PhotoImage(scaled_image)
- canvas.create_image(300, 300, image=scaled_image)
- canvas.update()
- current_size += zoom
- zoom += 2
- new_scale = new_scale[300 * 1200: 900 * 1200]
- pixels = []
- for i in range(0, len(new_scale), 1200):
- pixels.extend(new_scale[i + 300: i + 900])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement