turtle绘制五星红旗
时间: 2023-11-13 08:44:00 浏览: 76
下面是使用Python的turtle库绘制五星红旗的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#DE2910')
# 绘制大红色矩形
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 绘制大五角星
turtle.penup()
turtle.goto(-240, 120)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 绘制四个小五角星
positions = [(-120, 160), (-120, 80), (-60, 120), (-60, 40)]
for position in positions:
turtle.penup()
turtle.goto(position)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行代码后,将会得到一个绘制好的五星红旗图案。
阅读全文