Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_infinite_interpolation_5.py
- import random
- import tkinter as tk
- from PIL import Image,ImageTk
- ww = 600
- hh = 600
- root = tk.Tk()
- canvas = tk.Canvas(root, width=ww, height=hh)
- root.title("tk_infinite_interpolation.py")
- canvas.pack()
- rnd = 20
- output_scale = [(200, 200, 200)] * (ww * hh)
- preset_row = [(200, 200, 200)] * (ww - 4)
- pixels = [preset_row[:] for i in range(hh - 4)]
- vertical = [i for i in range(600)]
- def zoom():
- ppp = []
- del output_scale[:]
- for p in pixels:
- L = len(p)
- if L > ww:
- print(L)
- output_scale.extend(p)
- if len(p) > 596:
- ppp.append(p[2: ww-2])
- pixels[:] = ppp[2: hh-2]
- def rgb(x, y):
- r, g, b = output_scale[(x * hh) + y]
- i2, j2 = random.choice([(x,y-1),(x,y+1),(x-1,y),(x+1,y)])
- try:
- r0, g0, b0 = pixels[i2][j2]
- r = (r + r0) // 2
- g = (g + g0) // 2
- b = (b + b0) // 2
- except:
- 0
- r = min(255, max(0, r + random.randint(-rnd, rnd)))
- g = min(255, max(0, g + random.randint(-rnd, rnd)))
- b = min(255, max(0, b + random.randint(-rnd, rnd)))
- if horizontal == 1:
- pixels[x][y] = (r, g, b)
- else:
- pixels[x].insert(y, (r, g, b))
- img = Image.new("RGB", (ww, hh))
- ctr = 80
- while 1:
- for i in range(70,280,10):
- horizontal = 1
- for k in [(299 + i), (300 - i), (299 + ((i // 2) % ctr)), (300 - ((i // 2) % ctr))]:
- pixels.insert(k, preset_row[:])
- for j in range(596):
- rgb(k, j)
- horizontal = 0
- for j in vertical:
- rgb(j, 299 - i)
- rgb(j, 300 + i)
- rgb(j, 299 + ((i // 2) % ctr))
- rgb(j, 300 - ((i // 2) % ctr))
- zoom()
- img.putdata(output_scale)
- canvas.delete(tk.ALL)
- tk_image = ImageTk.PhotoImage(img)
- canvas.create_image(300, 300, image=tk_image)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement