Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Organic_Ripple_Polygon.py
- import tkinter as tk
- import math
- import random
- from PIL import Image, ImageTk, ImageDraw, ImageFilter
- WIDTH, HEIGHT = 640, 480
- CENTER_X, CENTER_Y = WIDTH // 2, HEIGHT // 2
- root = tk.Tk()
- root.title("# tk_Organic_Ripple_Polygon.py")
- canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg="black")
- canvas.pack()
- img_label = canvas.create_image(0, 0, anchor=tk.NW)
- img = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 64))
- ripples = []
- num_ripples = 6
- points_per_ripple = 60
- for ripple_idx in range(num_ripples):
- points = []
- start_dist = ripple_idx * 70
- for i in range(points_per_ripple):
- angle = (i / points_per_ripple) * 2 * math.pi
- points.append({
- 'angle': angle,
- 'dist': start_dist,
- 'dx': random.uniform(-5, 5),
- 'dy': random.uniform(-5, 5)
- })
- ripples.append({
- 'points': points,
- 'speed': 4.2
- })
- t = 0
- while True:
- img.paste((0, 0, 64), [0, 0, WIDTH, HEIGHT])
- t += 0.05
- draw = ImageDraw.Draw(img)
- for ripple in ripples:
- polygon_points = []
- for p in ripple['points']:
- p['dist'] += ripple['speed']
- if p['dist'] > 425:
- p['dist'] = 0
- p['dx'] = random.uniform(-25, 25)
- p['dy'] = random.uniform(-25, 25)
- x = CENTER_X + math.cos(p['angle']) * (p['dist']) + p['dx']
- y = CENTER_Y + math.sin(p['angle']) * (p['dist']) + p['dy']
- polygon_points.append((x, y))
- color = (255, 255, 255)
- draw.line(polygon_points + [polygon_points[0]], fill=color, width=18)
- blurred_img = img.filter(ImageFilter.GaussianBlur(radius=10))
- photo = ImageTk.PhotoImage(blurred_img)
- canvas.itemconfig(img_label, image=photo)
- root.update_idletasks()
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment