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,ImageEnhance
- 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 = 50
- 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]
- if 6 < iii < 580 and 6 < iii < 580:
- i = random.randint(-15, 15) + iii
- j = random.randint(-15, 15) + jjj
- r2, g2, b2 = pixels[i * 600 + j]
- r = (r*49 + r2) // 50
- g = (g*49 + g2) // 50
- b = (b*49 + b2) // 50
- i = iii * 2
- j = jjj * 2
- new_scale[i * 1200 + j] = (r, g, b)
- for i2, j2 in [(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()
- img.putdata(new_scale)
- # Resize the image using bi-cubic interpolation
- img = img.resize((1200, 1200), Image.BICUBIC)
- # Apply image enhancement for better color representation
- img = ImageEnhance.Sharpness(img).enhance(0.0001)
- 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