Advertisement
here2share

# tk_extra_colorful_zoom.py

Aug 21st, 2024
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. # tk_extra_colorful_zoom.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageFilter, ImageDraw
  5. import math
  6. import random
  7.  
  8. WW, HH = 600, 600
  9. WC, HC = WW // 2, HH // 2
  10. root = tk.Tk()
  11. root.title("# tk_extra_colorful_zoom")
  12. canvas = tk.Canvas(root, width=WW, height=HH)
  13. root.geometry("%dx%d+10+10" % (WW, HH))
  14. canvas.pack()
  15. image = Image.new("RGB", (WW, HH), 'black')
  16.  
  17. radius = min(WC, HC) // 2
  18. number_of_points = 12
  19.  
  20. def blob(image):
  21.     pixels = image.load()
  22.     r0, g0, b0 = [random.randint(0, 255) for _ in '...']
  23.     points = []
  24.     for j in range(number_of_points):
  25.         angle = 2 * math.pi * j / number_of_points
  26.         r = radius * random.uniform(0.01, 0.1)
  27.         a = angle * random.uniform(0.95, 1)
  28.         x = HC + r * math.cos(a) + 7
  29.         y = WC + r * math.sin(a) + 7
  30.         points.append((x, y))
  31.     draw = ImageDraw.Draw(image)
  32.     draw.polygon(points, fill=(r0, g0, b0))
  33.     return image
  34.  
  35. zoom = 50
  36. XY = []
  37. for x in range(-1, 4):
  38.     for y in range(-1, 4):
  39.         XY += [(zoom + x, zoom + y, WW-zoom + x, HH-zoom + y)]
  40. XY *= 10
  41.  
  42. def create_blurred_circle(size, center, radius, blur_radius):
  43.     theVoid = Image.new("RGBA", size, (0, 0, 0, 0))
  44.     draw = ImageDraw.Draw(theVoid)
  45.     draw.ellipse((center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius), fill=(0, 0, 0, 255))
  46.     return theVoid.filter(ImageFilter.GaussianBlur(blur_radius))
  47. theVoid = create_blurred_circle((WW, HH), (WC, HC), 24, 14)
  48.  
  49. canvas_image = canvas.create_image(0, 0, anchor=tk.NW)
  50.  
  51. while 1:
  52.     random.shuffle(XY)
  53.     for x1, y1, x2, y2 in XY:
  54.         image = image.crop((x1, y1, x2, y2))
  55.         image = image.resize((WW, HH))
  56.         image2 = blob(image)
  57.         image2 = Image.alpha_composite(image2.convert("RGBA"), theVoid).convert("RGB")
  58.        
  59.         gradient_photo = ImageTk.PhotoImage(image2)
  60.         canvas.itemconfig(canvas_image, image=gradient_photo)
  61.         canvas.update()
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement