Advertisement
here2share

# tk_infinite_interpolation_5.py

Feb 19th, 2023
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # tk_infinite_interpolation_5.py
  2.  
  3. import random
  4. import tkinter as tk
  5. from PIL import Image,ImageTk
  6.  
  7. ww = 600
  8. hh = 600
  9.  
  10. root = tk.Tk()
  11. canvas = tk.Canvas(root, width=ww, height=hh)
  12. root.title("tk_infinite_interpolation.py")
  13. canvas.pack()
  14.  
  15. rnd = 20
  16.  
  17. output_scale = [(200, 200, 200)] * (ww * hh)
  18. preset_row = [(200, 200, 200)] * (ww - 4)
  19. pixels = [preset_row[:] for i in range(hh - 4)]
  20.  
  21. vertical = [i for i in range(600)]
  22.  
  23. def zoom():
  24.     ppp = []
  25.     del output_scale[:]
  26.     for p in pixels:
  27.         L = len(p)
  28.         if L > ww:
  29.             print(L)
  30.         output_scale.extend(p)
  31.         if len(p) > 596:
  32.             ppp.append(p[2: ww-2])
  33.     pixels[:] = ppp[2: hh-2]
  34.  
  35. def rgb(x, y):
  36.     r, g, b = output_scale[(x * hh) + y]
  37.    
  38.     i2, j2 = random.choice([(x,y-1),(x,y+1),(x-1,y),(x+1,y)])
  39.     try:
  40.         r0, g0, b0 = pixels[i2][j2]
  41.         r = (r + r0) // 2
  42.         g = (g + g0) // 2
  43.         b = (b + b0) // 2
  44.     except:
  45.         0
  46.    
  47.     r = min(255, max(0, r + random.randint(-rnd, rnd)))
  48.     g = min(255, max(0, g + random.randint(-rnd, rnd)))
  49.     b = min(255, max(0, b + random.randint(-rnd, rnd)))
  50.     if horizontal == 1:
  51.         pixels[x][y] = (r, g, b)
  52.     else:
  53.         pixels[x].insert(y, (r, g, b))
  54.  
  55. img = Image.new("RGB", (ww, hh))
  56.  
  57. ctr = 80
  58. while 1:
  59.     for i in range(70,280,10):
  60.         horizontal = 1
  61.         for k in [(299 + i), (300 - i), (299 + ((i // 2) % ctr)), (300 - ((i // 2) % ctr))]:
  62.             pixels.insert(k, preset_row[:])
  63.             for j in range(596):
  64.                 rgb(k, j)
  65.         horizontal = 0
  66.         for j in vertical:
  67.             rgb(j, 299 - i)
  68.             rgb(j, 300 + i)
  69.             rgb(j, 299 + ((i // 2) % ctr))
  70.             rgb(j, 300 - ((i // 2) % ctr))
  71.        
  72.         zoom()
  73.         img.putdata(output_scale)
  74.  
  75.         canvas.delete(tk.ALL)
  76.         tk_image = ImageTk.PhotoImage(img)
  77.         canvas.create_image(300, 300, image=tk_image)
  78.         canvas.update()
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement