here2share

# tk_3D_Wobbling_Heart_Of_Particles.py

Sep 21st, 2025
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.70 KB | None | 0 0
  1. # tk_3D_Wobbling_Heart_Of_Particles.py
  2.  
  3. import tkinter as tk
  4. from PIL import Image, ImageTk, ImageDraw
  5. import math
  6. import random
  7. import time
  8.  
  9. canvas_size = 600
  10. base_scale = 12
  11. particle_count = 600
  12.  
  13. root = tk.Tk()
  14. root.title("3D Wobbling Heart Of Particles")
  15.  
  16. canvas = tk.Canvas(root, width=canvas_size, height=canvas_size)
  17. canvas.pack()
  18.  
  19. center_x = canvas_size // 2
  20. center_y = canvas_size // 2
  21.  
  22. wobble_phase = 0
  23.  
  24. heart_points = []
  25. for i in range(particle_count):
  26.     t = math.pi * 2 * i / particle_count
  27.     x = base_scale * 16 * math.sin(t) ** 3
  28.     y = -base_scale * (13 * math.cos(t) - 5 * math.cos(2 * t) -
  29.                        2 * math.cos(3 * t) - math.cos(4 * t))
  30.     heart_points.append((center_x + x, center_y + y))
  31.  
  32. particles = []
  33. for (x, y) in heart_points:
  34.     particle = {
  35.         'base_x': x - center_x,
  36.         'base_y': y - center_y,
  37.         'z': random.uniform(-5, 5),
  38.         'life': random.uniform(0.3, 1.0),
  39.         'size': 3,
  40.         'wobble_offset': 5,
  41.         'speed': random.uniform(0.07, 0.7)
  42.     }
  43.     particles.append(particle)
  44.  
  45. old_img = Image.new('RGB', (canvas_size, canvas_size))
  46. canvas_image_id = canvas.create_image(canvas_size // 2, canvas_size // 2)
  47. while 1:
  48.     new_img = Image.new('RGB', (canvas_size, canvas_size), 'yellow')
  49.     draw = ImageDraw.Draw(new_img)
  50.  
  51.     wobble_phase += 0.08
  52.  
  53.     throb_scale = 1.0 + 0.3 * math.sin(time.time() * 2) + 0.1 * math.sin(time.time() * 4.6)
  54.    
  55.     x_rotation = math.radians(5 * math.sin(wobble_phase))
  56.     y_rotation = math.radians(5 * math.cos(wobble_phase * 0.7))
  57.  
  58.     for particle in particles:
  59.         wobble_x = 15 * math.sin(wobble_phase + particle['wobble_offset'])
  60.         wobble_y = 8 * math.cos(wobble_phase * 1.3 + particle['wobble_offset'])
  61.         wobble_z = 10 * math.sin(wobble_phase * 0.7 + particle['wobble_offset'])
  62.  
  63.         base_x = particle['base_x']
  64.         base_y = particle['base_y']
  65.         base_z = particle['z']
  66.        
  67.         rotated_y = base_y * math.cos(x_rotation) - base_z * math.sin(x_rotation)
  68.         rotated_z1 = base_y * math.sin(x_rotation) + base_z * math.cos(x_rotation)
  69.        
  70.         rotated_x = base_x * math.cos(y_rotation) + rotated_z1 * math.sin(y_rotation)
  71.         rotated_z2 = -base_x * math.sin(y_rotation) + rotated_z1 * math.cos(y_rotation)
  72.  
  73.         z_factor = (100 + rotated_z2 + wobble_z) / 100
  74.  
  75.         final_x = center_x + (rotated_x + wobble_x) * z_factor * throb_scale
  76.         final_y = center_y + (rotated_y + wobble_y) * z_factor * throb_scale
  77.  
  78.         size = particle['size'] * z_factor
  79.  
  80.         x1 = int(final_x)
  81.         y1 = int(final_y)
  82.         x2 = int(final_x + size)
  83.         y2 = int(final_y + size)
  84.  
  85.         draw.ellipse([x1, y1, x2, y2], fill=(128, 0, 128))
  86.        
  87.     img = Image.blend(old_img, new_img, 0.5)
  88.     old_img = img.copy()
  89.     photo = ImageTk.PhotoImage(img)
  90.     canvas.itemconfig(canvas_image_id, image=photo)
  91.     canvas.photo = photo
  92.  
  93.     root.update()
  94.  
Add Comment
Please, Sign In to add comment