Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Reaction_Diffusion_RGB_Zoom.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageFilter
- import random
- ww = 560
- hh = 560
- ww0, hh0 = ww + 2, hh + 2
- center_x = ww // 2
- center_y = hh // 2
- root = tk.Tk()
- root.title("tk_Reaction_Diffusion_RGB_Zoom")
- root.geometry('+0+0')
- canvas = tk.Canvas(root, width=ww, height=hh, bg='white')
- ref_image = Image.new("RGB", (ww0, hh0), "white")
- pixel_data = []
- def gen(w,h):
- D = 20
- t = [z for z in range(256)]
- a = {}
- for z in t:
- v = min(z,256-D)
- a[z] = range(v,v+D)
- p = {}
- w2 = w/255.0
- h2 = h/255.0
- rgb = []
- for y in range(h):
- cy = int(y/h2)
- for x in range(w):
- cx = int(x/w2)
- r = 255-cx
- g = 255-cy
- b = int((cx+cy)/2)
- for bbb in a[b]:
- z = (r,g,bbb)
- try:
- p[z]
- except:
- break
- rgb.append(z)
- p[z] = 1
- return rgb
- pixel_data = gen(ww0,hh0)
- ref_image.putdata(pixel_data)
- def update_params_x(value):
- global x0
- x0 = float(value)
- def update_params_y(value):
- global y0
- y0 = float(value)
- def update_params_z(value):
- global z0
- z0 = float(value)
- x0 = 3
- y0 = 0
- z0 = 2
- x_slider = tk.Scale(root, from_=10, to=0, label='X', resolution=0.001, orient=tk.VERTICAL, bg="#FFFF00")
- x_slider.set(x0)
- y_slider = tk.Scale(root, from_=10, to=0, label='Y', resolution=0.001, orient=tk.VERTICAL, bg="#00FF00")
- y_slider.set(y0)
- z_slider = tk.Scale(root, from_=10, to=0, label='Z', resolution=0.001, orient=tk.VERTICAL, bg="#00C0FF")
- z_slider.set(z0)
- canvas.pack(side=tk.LEFT)
- x_slider.pack(side=tk.LEFT, fill='y')
- y_slider.pack(side=tk.LEFT, fill='y')
- z_slider.pack(side=tk.LEFT, fill='y')
- x_slider.config(command=lambda value: update_params_x(x_slider.get()))
- y_slider.config(command=lambda value: update_params_y(y_slider.get()))
- z_slider.config(command=lambda value: update_params_z(z_slider.get()))
- kernel_values = [0.05, 0.2, 0.05, 0.2, -1, 0.2, 0.05, 0.2, 0.05]
- def display():
- img = ref_image.crop((4, 4, ww + 4, hh + 4))
- img_tk = ImageTk.PhotoImage(img)
- canvas.create_image(0, 0, anchor="nw", image=img_tk)
- canvas.img = img_tk
- root.update()
- ref_image.putpixel((center_x, center_y - 1), (255, 255, 255))
- ref_image.putpixel((center_x, center_y + 1), (0, 0, 0))
- kernel = ImageFilter.Kernel((3, 3), kernel_values, scale=None, offset=0)
- while True:
- x, y, z = x0, y0, z0
- ref_image = ref_image.rotate(-0.5, resample=Image.BICUBIC)
- ref_image = ref_image.resize((ww + 8, hh + 8), resample=Image.BICUBIC)
- ref_image = ref_image.crop((4, 4, ww + 4, hh + 4))
- ref_image = ref_image.filter(kernel)
- ref_image = ref_image.filter(ImageFilter.GaussianBlur(x))
- ref_image = ref_image.filter(kernel)
- ref_image = ref_image.filter(ImageFilter.GaussianBlur(y))
- ref_image = ref_image.filter(kernel)
- ref_image = ref_image.filter(ImageFilter.GaussianBlur(z))
- ref_image = ref_image.filter(kernel)
- display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement