Advertisement
here2share

# tk_infinite_interpolation2.py

Jan 9th, 2023 (edited)
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 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 = 100
  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.             if 6 < iii < 580 and 6 < iii < 580:
  24.                 i = random.randint(-15, 15) + iii
  25.                 j = random.randint(-15, 15) + jjj
  26.                 r2, g2, b2 = pixels[i * 600 + j]
  27.                 r = (r*49 + r2) // 50
  28.                 g = (g*49 + g2) // 50
  29.                 b = (b*49 + b2) // 50
  30.             i = iii * 2
  31.             j = jjj * 2
  32.             new_scale[i * 1200 + j] = (r, g, b)
  33.             for i2, j2 in [(i+1,j),(i,j+1),(i+1,j+1)]:
  34.                 rrr = min(255, max(0, r + random.randint(-rnd, rnd)))
  35.                 ggg = min(255, max(0, g + random.randint(-rnd, rnd)))
  36.                 bbb = min(255, max(0, b + random.randint(-rnd, rnd)))
  37.                 new_scale[i2 * 1200 + j2] = (rrr, ggg, bbb)
  38.  
  39. img = Image.new("RGB", (1200, 1200))
  40. while 1:
  41.     interpolate()
  42.  
  43.     # Create a PIL.Image object from the pixel data
  44.     img.putdata(new_scale)
  45.  
  46.     zoom = 10
  47.     current_size = 600
  48.  
  49.     while current_size < 1200:
  50.         canvas.delete(tk.ALL)
  51.         sz = int(current_size)
  52.         scaled_image = img.resize((sz, sz), Image.ANTIALIAS)
  53.         scaled_image = ImageTk.PhotoImage(scaled_image)
  54.         canvas.create_image(300, 300, image=scaled_image)
  55.         canvas.update()
  56.         current_size += zoom
  57.         zoom += 2
  58.     new_scale = new_scale[300 * 1200: 900 * 1200]
  59.     pixels = []
  60.     for i in range(0, len(new_scale), 1200):
  61.         pixels.extend(new_scale[i + 300: i + 900])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement