here2share

# tk_Organic_Ripple_Polygon.py

Oct 10th, 2025 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. # tk_Organic_Ripple_Polygon.py
  2.  
  3. import tkinter as tk
  4. import math
  5. import random
  6. from PIL import Image, ImageTk, ImageDraw, ImageFilter
  7.  
  8. WIDTH, HEIGHT = 640, 480
  9. CENTER_X, CENTER_Y = WIDTH // 2, HEIGHT // 2
  10.  
  11. root = tk.Tk()
  12. root.title("# tk_Organic_Ripple_Polygon.py")
  13. canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg="black")
  14. canvas.pack()
  15. img_label = canvas.create_image(0, 0, anchor=tk.NW)
  16.  
  17. img = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 64))
  18.  
  19. ripples = []
  20. num_ripples = 6
  21. points_per_ripple = 60
  22.  
  23. for ripple_idx in range(num_ripples):
  24.     points = []
  25.     start_dist = ripple_idx * 70
  26.     for i in range(points_per_ripple):
  27.         angle = (i / points_per_ripple) * 2 * math.pi
  28.         points.append({
  29.             'angle': angle,
  30.             'dist': start_dist,
  31.             'dx': random.uniform(-5, 5),
  32.             'dy': random.uniform(-5, 5)
  33.         })
  34.     ripples.append({
  35.         'points': points,
  36.         'speed': 4.2
  37.     })
  38.  
  39. t = 0
  40.  
  41. while True:
  42.     img.paste((0, 0, 64), [0, 0, WIDTH, HEIGHT])
  43.     t += 0.05
  44.     draw = ImageDraw.Draw(img)
  45.    
  46.     for ripple in ripples:
  47.         polygon_points = []
  48.        
  49.         for p in ripple['points']:
  50.             p['dist'] += ripple['speed']
  51.             if p['dist'] > 425:
  52.                 p['dist'] = 0
  53.                 p['dx'] = random.uniform(-25, 25)
  54.                 p['dy'] = random.uniform(-25, 25)
  55.            
  56.             x = CENTER_X + math.cos(p['angle']) * (p['dist']) + p['dx']
  57.             y = CENTER_Y + math.sin(p['angle']) * (p['dist']) + p['dy']
  58.            
  59.             polygon_points.append((x, y))
  60.  
  61.         color = (255, 255, 255)
  62.        
  63.         draw.line(polygon_points + [polygon_points[0]], fill=color, width=18)
  64.    
  65.     blurred_img = img.filter(ImageFilter.GaussianBlur(radius=10))
  66.     photo = ImageTk.PhotoImage(blurred_img)
  67.     canvas.itemconfig(img_label, image=photo)
  68.     root.update_idletasks()
  69.     root.update()
Advertisement
Add Comment
Please, Sign In to add comment