Advertisement
here2share

# tk_infinite_interpolation.py

Jan 8th, 2023
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # tk_infinite_interpolation.py
  2.  
  3. import random
  4. import tkinter as tk
  5. from PIL import Image,ImageTk
  6.  
  7. root = tk.Tk()
  8. canvas = tk.Canvas(root, width=600, height=600)
  9. root.title("tk_infinite_interpolation.py")
  10. canvas.pack()
  11.  
  12. pixels = [(200, 200, 200)] * 600 * 600
  13. rnd = 10
  14.  
  15. NEW_SCALE_CONSTANT = [(0)] * 1200 * 1200
  16. new_scale = []
  17. def interpolate():
  18.     global new_scale
  19.     new_scale = NEW_SCALE_CONSTANT[:]
  20.     for iii in range(600):
  21.         for jjj in range(600):
  22.             r, g, b = pixels[iii * 600 + jjj]
  23.             i = iii * 2
  24.             j = jjj * 2
  25.             for i2, j2 in [(i,j),(i+1,j),(i,j+1),(i+1,j+1)]:
  26.                 rrr = min(255, max(0, r + random.randint(-rnd, rnd)))
  27.                 ggg = min(255, max(0, g + random.randint(-rnd, rnd)))
  28.                 bbb = min(255, max(0, b + random.randint(-rnd, rnd)))
  29.                 new_scale[i2 * 1200 + j2] = (rrr, ggg, bbb)
  30.  
  31. img = Image.new("RGB", (1200, 1200))
  32. while 1:
  33.     interpolate()
  34.  
  35.     # Create a PIL.Image object from the pixel data
  36.     img.putdata(new_scale)
  37.  
  38.     zoom = 10
  39.     current_size = 600
  40.  
  41.     while current_size < 1200:
  42.         canvas.delete(tk.ALL)
  43.         sz = int(current_size)
  44.         scaled_image = img.resize((sz, sz), Image.ANTIALIAS)
  45.         scaled_image = ImageTk.PhotoImage(scaled_image)
  46.         canvas.create_image(300, 300, image=scaled_image)
  47.         canvas.update()
  48.         current_size += zoom
  49.         zoom += 2
  50.     new_scale = new_scale[300 * 1200: 900 * 1200]
  51.     pixels = []
  52.     for i in range(0, len(new_scale), 1200):
  53.         pixels.extend(new_scale[i + 300: i + 900])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement