用Python画五星红旗
时间: 2023-11-16 20:48:10 浏览: 75
使用Python的turtle模块画国旗
好的,以下是用 Python 绘制五星红旗的代码:
```python
import turtle
# 设置画笔颜色
turtle.pencolor("red")
# 画红色背景
turtle.fillcolor("red")
turtle.begin_fill()
turtle.goto(300, 0)
turtle.goto(300, 200)
turtle.goto(-300, 200)
turtle.goto(-300, 0)
turtle.goto(300, 0)
turtle.end_fill()
# 画大星星
turtle.fillcolor("yellow")
turtle.penup()
turtle.goto(-120, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
# 画四个小星星
turtle.penup()
turtle.goto(-60, 150)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(24)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 80)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(24)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 20)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(24)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, -50)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(24)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
```
这样就可以绘制出五星红旗的图案了。
阅读全文