import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

# สร้างฟังก์ชันหัวใจ
def heart(t, scale=1):
    x = 16 * np.sin(t) ** 3
    y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
    return scale * x, scale * y

# ตั้งค่ากราฟ
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_xlim(-20, 20)
ax.set_ylim(-20, 20)
ax.set_aspect('equal')
ax.axis('off')

# เตรียมข้อมูลเส้นหัวใจ
t = np.linspace(0, 2 * np.pi, 1000)
lines = []
num_layers = 10  # จำนวนชั้นของเส้นหัวใจ
colors = plt.cm.Reds(np.linspace(0.3, 1, num_layers))  # ไล่เฉดสีแดง

# สร้างเส้นหัวใจหลายชั้น
for i in range(num_layers):
    line, = ax.plot([], [], lw=2, color=colors[i])
    lines.append(line)

# ฟังก์ชันอัปเดตแอนิเมชัน
def update(frame):
    for i, line in enumerate(lines):
        scale = 1 + 0.1 * np.sin(2 * np.pi * (frame / 50 + i / num_layers))  # สร้างการสั่นแบบคลื่น
        x, y = heart(t, scale)
        line.set_data(x, y)
    return lines

# สร้างแอนิเมชัน
ani = FuncAnimation(fig, update, frames=100, interval=50, blit=True)

# แสดงผล
plt.show()