import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as patches
def heart_curve(t): x = 16 * np.sin(t)**3 y = 13 * np.cos(t) - 5 * np.cos(2t) - 2 * np.cos(3t) - np.cos(4*t) return x, y
def draw_rose(ax, center, size, angle=0, color='red'): """ Рисует розу в точке center. size – общий размер цветка, angle – поворот (в радианах) для ориентации вдоль касательной. """ petals = 7 # количество лепестков petal_length = size * 0.8 # длина лепестка petal_width = size * 0.35 # ширина лепестка
for i in range(petals):
theta = 2 * np.pi * i / petals + angle
# Смещение центра эллипса от центра цветка
dx = petal_length * 0.5 * np.cos(theta)
dy = petal_length * 0.5 * np.sin(theta)
# Создаём эллипс (лепесток)
ellipse = patches.Ellipse(
(center[0] + dx, center[1] + dy),
width=petal_width, height=petal_length,
angle=np.degrees(theta),
facecolor=color, edgecolor='darkred', alpha=0.85
)
ax.add_patch(ellipse)
# Центральная часть – жёлтая сердцевина
circle = patches.Circle(center, radius=size*0.15,
facecolor='gold', edgecolor='orange')
ax.add_patch(circle)
t = np.linspace(0, 2*np.pi, 500) x, y = heart_curve(t)
scale = 0.6 x = x * scale y = y * scale
fig, ax = plt.subplots(figsize=(10, 10)) ax.set_aspect('equal') ax.axis('off')
ax.set_facecolor('#1a1a2e')
ax.plot(x, y, color='white', linewidth=1.5, alpha=0.3)
step = 6 indices = np.arange(0, len(t), step)
if indices[-1] != len(t)-1: indices = np.append(indices, len(t)-1)
for i in indices: cx = x[i] cy = y[i]
# Вычисляем угол касательной (производная через центральную разность)
i_prev = (i - 1) % len(t)
i_next = (i + 1) % len(t)
dt = t[i_next] - t[i_prev]
if dt == 0:
angle = 0
else:
dx = (x[i_next] - x[i_prev]) / dt
dy = (y[i_next] - y[i_prev]) / dt
angle = np.arctan2(dy, dx)
# Размер цветка (можно варьировать для динамики)
size = 0.18 * scale + 0.04 * np.random.randn()
size = max(0.08, min(0.30, size)) # ограничиваем
# Цвет – оттенки красного/розового
color = plt.cm.Reds(np.random.uniform(0.5, 0.95))
# Рисуем розу
draw_rose(ax, (cx, cy), size, angle, color)
plt.title("❤️ Сердце из роз", fontsize=20, color='white', pad=20) plt.tight_layout() plt.show()