Advertisement
here2share

# tk_layer_gradient_art_animation.py

Jan 1st, 2023 (edited)
1,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. # tk_layer_gradient_art_animation.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk
  5. import random
  6.  
  7. root = tk.Tk()
  8. root.title("Layer Gradient Art Animation")
  9.  
  10. canvas_width = 600
  11. canvas_height = 600
  12.  
  13. canvas = tk.Canvas(root, width=canvas_width, height=canvas_height)
  14. canvas.pack()
  15.  
  16. gradient_art = Image.new("RGB", (canvas_width, canvas_height), "gray")
  17.  
  18. gradient = [z for z in range(256)]
  19. gradient = gradient[1:-1] + gradient[::-1]
  20. L = len(gradient)
  21.  
  22. while 1:
  23.     xr1, xg1, xb1 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  24.     xr2, xg2, xb2 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  25.     yr1, yg1, yb1 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  26.     yr2, yg2, yb2 = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
  27.  
  28.     for x in range(canvas_width):
  29.         r0 = (xr1 + (xr2 - xr1) * (x / canvas_width))
  30.         g0 = (xg1 + (xg2 - xg1) * (x / canvas_width))
  31.         b0 = (xb1 + (xb2 - xb1) * (x / canvas_width))
  32.         for y in range(canvas_height):
  33.             prev_r, prev_g, prev_b = gradient_art.getpixel((x, y))
  34.             r = gradient[(prev_r + int((r0 + (yr1 + (yr2 - yr1) * (y / canvas_height))) / 2)) % L]
  35.             g = gradient[(prev_g + int((g0 + (yg1 + (yg2 - yg1) * (y / canvas_height))) / 2)) % L]
  36.             b = gradient[(prev_b + int((b0 + (yb1 + (yb2 - yb1) * (y / canvas_height))) / 2)) % L]
  37.             gradient_art.putpixel((x, y), (r, g, b))
  38.    
  39.     image = ImageTk.PhotoImage(gradient_art)
  40.     canvas.create_image(canvas_width / 2, canvas_height / 2, image=image)
  41.     canvas.update()
  42.  
  43. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement