1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Circle, Polygon, FancyBboxPatch
import numpy as np
def draw_snake_art_optimized_v4():
# 设置画布
fig, ax = plt.subplots(figsize=(12, 10))
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.axis('off')
ax.set_facecolor('white') # 背景色
# 绘制“2025”数字块
def draw_number_block(x, y, number, color="red", edge_color="black"):
block = FancyBboxPatch((x, y), 3, 5, boxstyle="round,pad=0.2", color=color, edgecolor=edge_color, linewidth=2)
ax.add_patch(block)
ax.text(x + 1.5, y + 2.5, number, color="black", fontsize=30, ha="center", va="center", fontweight="bold")
# 绘制数字
draw_number_block(-9, -6, "2")
draw_number_block(-5, -6, "0")
draw_number_block(-1, -6, "2")
draw_number_block(3, -6, "5")
# 绘制小蛇身体(用平滑的样条曲线模拟)
t = np.linspace(0, 2 * np.pi, 500)
x_snake = 5 * np.sin(t) * np.exp(-0.05 * t) # 小蛇身体的横向分布
y_snake = 3 * np.cos(t) * np.exp(-0.05 * t) + 3 # 小蛇身体的纵向分布
ax.plot(x_snake, y_snake, color="yellow", linewidth=12, zorder=2) # 黄色曲线表示蛇的身体
# 蛇头
head_x, head_y = x_snake[0], y_snake[0]
head = Circle((head_x, head_y), radius=1.5, color="yellow", ec="black", lw=2, zorder=3)
ax.add_patch(head)
# 蛇头装饰(花朵)
def draw_flower(x, y, size=0.3, color="pink"):
for angle in range(0, 360, 72):
petal_x = x + size * np.cos(np.radians(angle))
petal_y = y + size * np.sin(np.radians(angle))
petal = Circle((petal_x, petal_y), radius=size * 0.6, color=color, ec="black", lw=1)
ax.add_patch(petal)
center = Circle((x, y), radius=size * 0.5, color="red", zorder=4)
ax.add_patch(center)
draw_flower(head_x + 0.5, head_y + 1)
draw_flower(head_x - 0.8, head_y + 0.8)
draw_flower(head_x, head_y - 1.5)
# 蛇的表情细节
# 眼睛
ax.add_patch(Circle((head_x - 0.5, head_y + 0.5), radius=0.2, color="black", zorder=4)) # 左眼
ax.add_patch(Circle((head_x + 0.5, head_y + 0.5), radius=0.2, color="black", zorder=4)) # 右眼
ax.add_patch(Circle((head_x - 0.5, head_y + 0.5), radius=0.1, color="white", zorder=5)) # 左眼高光
ax.add_patch(Circle((head_x + 0.5, head_y + 0.5), radius=0.1, color="white", zorder=5)) # 右眼高光
# 腮红
ax.add_patch(Circle((head_x - 1, head_y - 0.5), radius=0.3, color="pink", alpha=0.7, zorder=3)) # 左腮红
ax.add_patch(Circle((head_x + 1, head_y - 0.5), radius=0.3, color="pink", alpha=0.7, zorder=3)) # 右腮红
# 嘴巴和舌头
ax.text(head_x, head_y - 0.7, "v", fontsize=30, color="black", ha="center", zorder=4) # 嘴巴
tongue = Polygon([[head_x, head_y - 1.3], [head_x + 0.3, head_y - 1.8], [head_x - 0.3, head_y - 1.8]],
closed=True, color="red", zorder=4)
ax.add_patch(tongue)
# 背景装饰(星星和花瓣)
def draw_star(x, y, size=0.5, color="gold"):
for angle in range(0, 360, 144):
star_x = x + size * np.cos(np.radians(angle))
star_y = y + size * np.sin(np.radians(angle))
ax.plot([x, star_x], [y, star_y], color=color, lw=2)
draw_star(2, 5, size=1)
draw_star(-6, 3, size=1)
draw_star(6, 0, size=1)
# 绘制左边的文字 "蛇年有福"
x_text_left, y_text_left = -7, 6 # 左侧文字位置
for i, char in enumerate("蛇年有福"):
ax.text(x_text_left, y_text_left - i * 2, char, fontsize=25, color="yellow", ha="center", va="center",
fontweight="bold", bbox=dict(boxstyle="round", facecolor="red", edgecolor="black", pad=0.5),
fontname="SimHei") # 指定字体为SimHei(黑体)
# 绘制右边的文字 "平安喜乐"
x_text_right, y_text_right = 7, 6 # 右侧文字位置
for i, char in enumerate("平安喜乐"):
ax.text(x_text_right, y_text_right - i * 2, char, fontsize=25, color="yellow", ha="center", va="center",
fontweight="bold", bbox=dict(boxstyle="round", facecolor="red", edgecolor="black", pad=0.5),
fontname="SimHei") # 指定字体为SimHei(黑体)
# 显示图像
plt.show()
# 调用绘制函数
draw_snake_art_optimized_v4()
|