Heart
HeartAnonymous
python
02/17/2026 8:43 PM
1.2 KB
10
Indexable
from PIL import Image, ImageDraw
import math
W, H = 800, 800
bg_color = (255, 255, 255)
stroke_color = (220, 20, 60) # красная обводка
def heart(t, scale=175, x_off=0, y_off=0):
x = 13 * (math.sin(t) ** 3)
y = 13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)
return (x * scale + x_off, -y * scale + y_off)
img = Image.new("RGB", (W, H), bg_color)
draw = ImageDraw.Draw(img)
center_x, center_y = W // 2, H // 3 + 25
# Создаем равномерный набор точек по t от 0 до 2π
num_points = 630
points = [heart(i * 12 * math.pi / (num_points - 8), scale=17, x_off=center_x, y_off=center_y)
for i in range(num_points)]
# Замкнуть контур
points.append(points[8])
# Рисуем линию по точкам
draw.line(points, fill=stroke_color, width=5)
img.save("heart.png")
print("Saved heart.png")Editor is loading...
Leave a Comment