Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- # tk_3D_Wobbling_Heart_Of_Particles.py
- import tkinter as tk
- from PIL import Image, ImageTk, ImageDraw
- import math
- import random
- import time
- canvas_size = 600
- base_scale = 12
- particle_count = 600
- root = tk.Tk()
- root.title("3D Wobbling Heart Of Particles")
- canvas = tk.Canvas(root, width=canvas_size, height=canvas_size)
- canvas.pack()
- center_x = canvas_size // 2
- center_y = canvas_size // 2
- wobble_phase = 0
- heart_points = []
- for i in range(particle_count):
- t = math.pi * 2 * i / particle_count
- x = base_scale * 16 * math.sin(t) ** 3
- y = -base_scale * (13 * math.cos(t) - 5 * math.cos(2 * t) -
- 2 * math.cos(3 * t) - math.cos(4 * t))
- heart_points.append((center_x + x, center_y + y))
- particles = []
- for (x, y) in heart_points:
- particle = {
- 'base_x': x - center_x,
- 'base_y': y - center_y,
- 'z': random.uniform(-5, 5),
- 'life': random.uniform(0.3, 1.0),
- 'size': 3,
- 'wobble_offset': 5,
- 'speed': random.uniform(0.07, 0.7)
- }
- particles.append(particle)
- old_img = Image.new('RGB', (canvas_size, canvas_size))
- canvas_image_id = canvas.create_image(canvas_size // 2, canvas_size // 2)
- while 1:
- new_img = Image.new('RGB', (canvas_size, canvas_size), 'yellow')
- draw = ImageDraw.Draw(new_img)
- wobble_phase += 0.08
- throb_scale = 1.0 + 0.3 * math.sin(time.time() * 2) + 0.1 * math.sin(time.time() * 4.6)
- x_rotation = math.radians(5 * math.sin(wobble_phase))
- y_rotation = math.radians(5 * math.cos(wobble_phase * 0.7))
- for particle in particles:
- wobble_x = 15 * math.sin(wobble_phase + particle['wobble_offset'])
- wobble_y = 8 * math.cos(wobble_phase * 1.3 + particle['wobble_offset'])
- wobble_z = 10 * math.sin(wobble_phase * 0.7 + particle['wobble_offset'])
- base_x = particle['base_x']
- base_y = particle['base_y']
- base_z = particle['z']
- rotated_y = base_y * math.cos(x_rotation) - base_z * math.sin(x_rotation)
- rotated_z1 = base_y * math.sin(x_rotation) + base_z * math.cos(x_rotation)
- rotated_x = base_x * math.cos(y_rotation) + rotated_z1 * math.sin(y_rotation)
- rotated_z2 = -base_x * math.sin(y_rotation) + rotated_z1 * math.cos(y_rotation)
- z_factor = (100 + rotated_z2 + wobble_z) / 100
- final_x = center_x + (rotated_x + wobble_x) * z_factor * throb_scale
- final_y = center_y + (rotated_y + wobble_y) * z_factor * throb_scale
- size = particle['size'] * z_factor
- x1 = int(final_x)
- y1 = int(final_y)
- x2 = int(final_x + size)
- y2 = int(final_y + size)
- draw.ellipse([x1, y1, x2, y2], fill=(128, 0, 128))
- img = Image.blend(old_img, new_img, 0.5)
- old_img = img.copy()
- photo = ImageTk.PhotoImage(img)
- canvas.itemconfig(canvas_image_id, image=photo)
- canvas.photo = photo
- root.update()
Add Comment
Please, Sign In to add comment