Advertisement
here2share

# tk_infinite_interpolation_6.py

Feb 28th, 2023 (edited)
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. # tk_infinite_interpolation_6.py
  2.  
  3. import tkinter as tk
  4. from random import randint, shuffle, choice
  5. import sys
  6. import os
  7. from PIL import ImageGrab, Image, ImageTk
  8.  
  9. ww = 600
  10. hh = 600
  11.  
  12. root = tk.Tk()
  13. canvas = tk.Canvas(root, width=ww, height=hh)
  14. root.title("tk_infinite_interpolation.py")
  15. root.geometry(f"{ww}x{hh}+10+10")
  16. canvas.pack()
  17.  
  18. rnd = 60
  19.  
  20. dir_path = os.path.dirname(os.path.realpath(sys.argv[0]))
  21.  
  22. def add_path(file):
  23.     return os.path.join(dir_path, file)
  24.  
  25. png_file = add_path('tmp.png')
  26.  
  27. vertical = [i for i in range(hh)]
  28.  
  29. XXYY = {}
  30.    
  31. def rgbXY(x, y, z):
  32.     try:
  33.         XXYY[z].append((x,y))
  34.     except:
  35.         XXYY[z] = []
  36.         XXYY[z].append((x,y))
  37.    
  38. def rgb(x, y):
  39.     r, g, b = img.getpixel((x, y))
  40.    
  41.     i2, j2 = choice([(x,y-1),(x,y+1),(x-1,y),(x+1,y)])
  42.     r0, g0, b0 = img.getpixel((i2, j2))
  43.     r = (r + r0) // 2
  44.     g = (g + g0) // 2
  45.     b = (b + b0) // 2
  46.    
  47.     r = min(255, max(0, r + randint(-rnd, rnd)))
  48.     g = min(255, max(0, g + randint(-rnd, rnd)))
  49.     b = min(255, max(0, b + randint(-rnd, rnd)))
  50.  
  51.     img.putpixel((x, y), (r, g ,b))
  52.  
  53. ctr = 80
  54. for i in range(70,280,10):
  55.     iii = len(XXYY)
  56.     v = 0
  57.     for k in [(299 + i), (300 - i), (299 + ((i // 2) % ctr)), (300 - ((i // 2) % ctr))]:
  58.         for j in range(596):
  59.             rgbXY(k, j, v)
  60.         v += 1
  61.     for j in vertical:
  62.         rgbXY(j, 299 - i, v)
  63.         rgbXY(j, 300 + i, v + 1)
  64.         rgbXY(j, 299 + ((i // 2) % ctr), v + 2)
  65.         rgbXY(j, 300 - ((i // 2) % ctr), v + 3)
  66.  
  67. L = len(XXYY[0])
  68. injections = 800
  69.  
  70. def pos():
  71.     return canvas.winfo_rootx() * 1.5, canvas.winfo_rooty() * 1.5
  72.  
  73. sz = 620
  74. canvas.create_rectangle(0, 0, ww, hh, fill='gray')
  75. canvas.update()
  76. cx, cy = pos()
  77. while 1:
  78.     png = ImageGrab.grab((cx, cy, cx + ww * 1.5, cy + hh * 1.5))
  79.     img = png.resize((sz, sz))
  80.  
  81.     for i in range(8):
  82.         shuffle(XXYY[i])
  83.  
  84.     for j in range(injections):
  85.         i = j % 8
  86.         x, y = XXYY[i][j]
  87.         rgb(x,y)
  88.  
  89.     pil_img = ImageTk.PhotoImage(img)
  90.     canvas.create_image(-10, -10, anchor='nw', image=pil_img)
  91.     img.save(png_file)
  92.     canvas.update()
  93.  
  94.     cx, cy = pos()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement