Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_infinite_interpolation_6.py
- import tkinter as tk
- from random import randint, shuffle, choice
- import sys
- import os
- from PIL import ImageGrab, Image, ImageTk
- ww = 600
- hh = 600
- root = tk.Tk()
- canvas = tk.Canvas(root, width=ww, height=hh)
- root.title("tk_infinite_interpolation.py")
- root.geometry(f"{ww}x{hh}+10+10")
- canvas.pack()
- rnd = 60
- dir_path = os.path.dirname(os.path.realpath(sys.argv[0]))
- def add_path(file):
- return os.path.join(dir_path, file)
- png_file = add_path('tmp.png')
- vertical = [i for i in range(hh)]
- XXYY = {}
- def rgbXY(x, y, z):
- try:
- XXYY[z].append((x,y))
- except:
- XXYY[z] = []
- XXYY[z].append((x,y))
- def rgb(x, y):
- r, g, b = img.getpixel((x, y))
- i2, j2 = choice([(x,y-1),(x,y+1),(x-1,y),(x+1,y)])
- r0, g0, b0 = img.getpixel((i2, j2))
- r = (r + r0) // 2
- g = (g + g0) // 2
- b = (b + b0) // 2
- r = min(255, max(0, r + randint(-rnd, rnd)))
- g = min(255, max(0, g + randint(-rnd, rnd)))
- b = min(255, max(0, b + randint(-rnd, rnd)))
- img.putpixel((x, y), (r, g ,b))
- ctr = 80
- for i in range(70,280,10):
- iii = len(XXYY)
- v = 0
- for k in [(299 + i), (300 - i), (299 + ((i // 2) % ctr)), (300 - ((i // 2) % ctr))]:
- for j in range(596):
- rgbXY(k, j, v)
- v += 1
- for j in vertical:
- rgbXY(j, 299 - i, v)
- rgbXY(j, 300 + i, v + 1)
- rgbXY(j, 299 + ((i // 2) % ctr), v + 2)
- rgbXY(j, 300 - ((i // 2) % ctr), v + 3)
- L = len(XXYY[0])
- injections = 800
- def pos():
- return canvas.winfo_rootx() * 1.5, canvas.winfo_rooty() * 1.5
- sz = 620
- canvas.create_rectangle(0, 0, ww, hh, fill='gray')
- canvas.update()
- cx, cy = pos()
- while 1:
- png = ImageGrab.grab((cx, cy, cx + ww * 1.5, cy + hh * 1.5))
- img = png.resize((sz, sz))
- for i in range(8):
- shuffle(XXYY[i])
- for j in range(injections):
- i = j % 8
- x, y = XXYY[i][j]
- rgb(x,y)
- pil_img = ImageTk.PhotoImage(img)
- canvas.create_image(-10, -10, anchor='nw', image=pil_img)
- img.save(png_file)
- canvas.update()
- cx, cy = pos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement