利用turtle库绘制一个五星红旗
时间: 2023-05-21 16:00:48 浏览: 119
以下是利用turtle库绘制五星红旗的代码:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(600, 400)
turtle.bgcolor('#DE2910')
# 绘制红色矩形
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
for i in range(2):
turtle.forward(400)
turtle.right(90)
turtle.forward(280)
turtle.right(90)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-120, 60)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 绘制四个小星星
turtle.penup()
turtle.goto(-60, 120)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 80)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 40)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 0)
turtle.pendown()
turtle.color('#FFDE00', '#FFDE00')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行上述代码,即可在窗口中看到绘制的五星红旗。
阅读全文