Skip to content

Instantly share code, notes, and snippets.

@HUGHNew
Created October 3, 2025 06:54
Show Gist options
  • Save HUGHNew/0ba76255d997ad0b58b0263611af0e54 to your computer and use it in GitHub Desktop.
Save HUGHNew/0ba76255d997ad0b58b0263611af0e54 to your computer and use it in GitHub Desktop.
Flag for modern MING
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Ellipse, Rectangle
# 定义颜色常量
RED = "#DE2910"
YELLOW = "#FFD700"
BLACK = "#111111"
def draw_modern_ming_flag():
"""
自定义新汉旗: 兼并五朝特色
1. 取色: 黑红黄
- 黑为基 承商玄秦水 忆旧时风水
- 红为底 顺唐明火德 延今朝血脉
- 黄为正 续炎黄土德 复日月所照
2. 取形: 圆矩
- 矩为形之所在
- 圆为神之之所照
- 仍有国基未复
"""
# 创建画布和坐标轴
fig, ax = plt.subplots(figsize=(6, 4))
ax.set_facecolor(BLACK)
# 设置矩形尺寸(3:2比例)
rect_width, rect_height = 6, 4
rect_center = (rect_width / 2, rect_height / 2)
# 1. 绘制黑色边框矩形
border_rect = Rectangle((0, 0), rect_width, rect_height, facecolor=BLACK)
ax.add_patch(border_rect)
# 2. 绘制红色椭圆(与矩形内切)
ellipse = Ellipse(
rect_center, rect_width, rect_height, facecolor=RED, edgecolor=RED, linewidth=2
)
ax.add_patch(ellipse)
# 3. 绘制黄色大圆(直径为矩形短边的一半)
big_circle_radius = rect_height / 4
big_circle = Circle(rect_center, big_circle_radius, facecolor=YELLOW, linewidth=2)
ax.add_patch(big_circle)
# 4. 计算大圆左侧切点
left_tangent_point = (rect_center[0] - big_circle_radius, rect_center[1])
# 5. 绘制掩月圆(红色,用于裁剪效果)
mask_circle_radius = big_circle_radius * 0.9 # 0.45 * 2 # 45年再驱外蛮
mask_circle_center = (
left_tangent_point[0] + 0.707 * big_circle_radius, # 0.707**2 ~= 0.5 日月同光
rect_center[1],
)
mask_circle = Circle(
mask_circle_center, mask_circle_radius, facecolor=RED, linewidth=2
)
ax.add_patch(mask_circle)
# 6. 绘制内切圆
inner_radius = big_circle_radius * 0.707
inner_center = (left_tangent_point[0] + inner_radius, rect_center[1])
inner_circle = Circle(inner_center, inner_radius, facecolor=YELLOW, linewidth=2)
ax.add_patch(inner_circle)
# 设置坐标轴属性
ax.set_xlim(0, rect_width)
ax.set_ylim(0, rect_height)
ax.set_aspect("equal")
ax.axis("off") # 隐藏坐标轴
plt.tight_layout()
return fig, ax
# 绘制图形
if __name__ == "__main__":
fig, ax = draw_modern_ming_flag()
# plt.show()
fig.savefig("flag.png", bbox_inches="tight", pad_inches=0, facecolor=BLACK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment