利用turtle库绘制五星红旗
时间: 2023-05-21 15:00:36 浏览: 133
可以使用以下代码绘制五星红旗:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色和填充颜色
turtle.color("red", "red")
# 绘制矩形
turtle.begin_fill()
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.end_fill()
# 绘制大星星
turtle.color("yellow", "yellow")
turtle.begin_fill()
turtle.penup()
turtle.goto(-200, 120)
turtle.pendown()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 绘制四个小星星
turtle.color("yellow", "yellow")
turtle.begin_fill()
turtle.penup()
turtle.goto(-80, 160)
turtle.pendown()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.color("yellow", "yellow")
turtle.begin_fill()
turtle.penup()
turtle.goto(-60, 80)
turtle.pendown()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.color("yellow", "yellow")
turtle.begin_fill()
turtle.penup()
turtle.goto(-60, 0)
turtle.pendown()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.color("yellow", "yellow")
turtle.begin_fill()
turtle.penup()
turtle.goto(-80, -80)
turtle.pendown()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行以上代码即可绘制出五星红旗。
阅读全文