Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 512x512_rgb_gel_ctrl.py
- import tkinter as tk
- import random
- from PIL import Image, ImageTk, ImageFilter
- ww = 512
- hh = 512
- root = tk.Tk()
- root.title("512x512_image_generator")
- root.geometry("%dx%d+%d+%d" %(ww, hh, 10, 10))
- canvas = tk.Canvas(root, width=ww, height=hh)
- canvas.pack()
- colors = []
- t = [z for z in range(0, 256, 15)]
- for r in t:
- for g in t:
- for b in t:
- colors += [(r, g, b, 255)]
- Lc = len(colors)
- def generate(event=None):
- for size in layers:
- interpolate(size)
- draw()
- def interpolate(size):
- global idx
- idx += 1
- img = Image.new("RGBA", (size, size))
- pixels = img.load()
- for y in range(size):
- for x in range(size):
- color = colors.pop(idx**3)
- idx = (idx + 1) % 7
- pixels[x, y] = color
- colors.append(color)
- img = img.resize((ww, hh))
- layers[size] = img
- def draw(event=None):
- buffer = Image.new("RGBA", (ww, hh), (255, 255, 255, 255))
- for size, layer_image in layers.items():
- if size != 4:
- alpha = float(opacity_slider[size].get()) / 800.0
- else:
- alpha = 1
- buffer = Image.blend(buffer, layer_image, alpha)
- buffer = buffer.point(lambda x: x // 25 * 25)
- photo = ImageTk.PhotoImage(buffer)
- canvas.create_image(0, 0, anchor=tk.NW, image=photo)
- canvas.image = photo
- opacity_label = tk.Toplevel(root)
- opacity_title = tk.Label(opacity_label, text="Press Spacebar To Randomize")
- opacity_title.pack()
- opacity_slider = {}
- layers = {}
- idx = 0
- size = 8
- for i in (512, 512, 96):
- opacity_slider[size] = tk.Scale(opacity_label, from_=512, to=0, orient=tk.VERTICAL, label=size, command=draw)
- opacity_slider[size].pack(side=tk.LEFT, fill='both', expand=True)
- opacity_slider[size].set(i)
- interpolate(size)
- size *= 2
- canvas.update()
- t = opacity_label.winfo_width()
- opacity_label.geometry("%dx300+%d+%d" %(t, 50, 50))
- for t in (root, opacity_label):
- t.bind("<space>", generate)
- opacity_label.wm_transient(root)
- draw()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement