Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_layer_gradient_art_animation.py
- import tkinter as tk
- from PIL import Image, ImageTk
- import random
- root = tk.Tk()
- root.title("Layer Gradient Art Animation")
- canvas_width = 600
- canvas_height = 600
- canvas = tk.Canvas(root, width=canvas_width, height=canvas_height)
- canvas.pack()
- gradient_art = Image.new("RGB", (canvas_width, canvas_height), "gray")
- gradient = [z for z in range(256)]
- gradient = gradient[1:-1] + gradient[::-1]
- L = len(gradient)
- while 1:
- xr1, xg1, xb1 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- xr2, xg2, xb2 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- yr1, yg1, yb1 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- yr2, yg2, yb2 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
- for x in range(canvas_width):
- r0 = (xr1 + (xr2 - xr1) * (x / canvas_width))
- g0 = (xg1 + (xg2 - xg1) * (x / canvas_width))
- b0 = (xb1 + (xb2 - xb1) * (x / canvas_width))
- for y in range(canvas_height):
- prev_r, prev_g, prev_b = gradient_art.getpixel((x, y))
- r = gradient[(prev_r + int((r0 + (yr1 + (yr2 - yr1) * (y / canvas_height))) / 2)) % L]
- g = gradient[(prev_g + int((g0 + (yg1 + (yg2 - yg1) * (y / canvas_height))) / 2)) % L]
- b = gradient[(prev_b + int((b0 + (yb1 + (yb2 - yb1) * (y / canvas_height))) / 2)) % L]
- gradient_art.putpixel((x, y), (r, g, b))
- image = ImageTk.PhotoImage(gradient_art)
- canvas.create_image(canvas_width / 2, canvas_height / 2, image=image)
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement