# 用 Python 给自己的头像加一个小国旗（小月饼）

## 国旗

```turtle.setup(600, 400, 0, 0)
turtle.bgcolor("red")```

```turtle.fillcolor("yellow")
turtle.color('yellow')
turtle.speed(10)
# 主星
turtle.begin_fill()
turtle.up()
turtle.goto(-280,100)
turtle.down()
for i in range (5):
turtle.forward(150)
turtle.right(144)
turtle.end_fill()```

```# 副星1
turtle.begin_fill()
turtle.up()
turtle.goto(-100,180)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
# 副星2
turtle.begin_fill()
turtle.up()
turtle.goto(-50,110)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
# 副星3
turtle.begin_fill()
turtle.up()
turtle.goto(-40,50)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
# 副星4
turtle.begin_fill()
turtle.up()
turtle.goto(-100,10)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()```

## 月饼

```turtle.speed(100)
turtle.color("#F5E16F")
for i in range(20):
# 顺时针移动18度
turtle.right(18)
turtle.begin_fill()
# 向前移动的距离
turtle.forward(220)
# 画半径为 40 的半圆
turtle.circle(40, 180)
# 画完半圆之后回到（0，0）
turtle.goto(0, 0)
turtle.right(360)
turtle.end_fill()```

```# 设置画笔粗细
turtle.pensize(20)
# 填充颜色（外部、内部）
turtle.color("#F5E16F", "#FF9933")
goto(0, -200)
# 准备开始填充
turtle.begin_fill()
turtle.circle(200)
# 填充结束
turtle.end_fill()
turtle.right(360)
turtle.color('#F5E16F')
goto(0, -180)
for i in range(12):
turtle.begin_fill()
turtle.circle(60, 120)
turtle.left(180)
turtle.circle(60, 120)
turtle.end_fill()```

```turtle.color("#F5E16F")
turtle.write("豆沙", font=("隶书", 60, "bold"))```

## 头像加国旗（月饼）

```# 读取头像和国旗图案
# 获取头像和国旗图案宽度
w_flag, h_flag = img_flag.shape[:2]
# 计算图案缩放比例
scale = w_head / w_flag / 4
# 缩放图案
img_flag = cv2.resize(img_flag, (0, 0), fx=scale, fy=scale)
# 获取缩放后新宽度
w_flag, h_flag = img_flag.shape[:2]
# 按 3 个通道合并图片
for c in range(0, 3):
# 保存最终结果