用python的tuetle画五星红旗
时间: 2023-10-10 18:12:08 浏览: 94
好的,以下是使用 Python 的 turtle 库画五星红旗的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色和填充颜色
turtle.color('red', 'red')
# 绘制矩形
turtle.begin_fill()
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
for i in range(2):
turtle.forward(500)
turtle.right(90)
turtle.forward(333)
turtle.right(90)
turtle.end_fill()
# 绘制大五角星
turtle.color('yellow', 'yellow')
turtle.begin_fill()
turtle.penup()
turtle.goto(-190, 135)
turtle.pendown()
turtle.setheading(162)
turtle.forward(150)
turtle.setheading(0)
for i in range(4):
turtle.right(72)
turtle.forward(150)
turtle.end_fill()
# 绘制四个小五角星
turtle.color('yellow', 'yellow')
turtle.begin_fill()
turtle.penup()
turtle.goto(-85, 190)
turtle.pendown()
turtle.setheading(162)
turtle.forward(60)
turtle.setheading(0)
for i in range(4):
turtle.right(72)
turtle.forward(60)
turtle.end_fill()
turtle.penup()
turtle.goto(-85, 100)
turtle.pendown()
turtle.setheading(162)
turtle.begin_fill()
turtle.forward(60)
turtle.setheading(0)
for i in range(4):
turtle.right(72)
turtle.forward(60)
turtle.end_fill()
turtle.penup()
turtle.goto(-10, 160)
turtle.pendown()
turtle.setheading(162)
turtle.begin_fill()
turtle.forward(60)
turtle.setheading(0)
for i in range(4):
turtle.right(72)
turtle.forward(60)
turtle.end_fill()
turtle.penup()
turtle.goto(-10, 70)
turtle.pendown()
turtle.setheading(162)
turtle.begin_fill()
turtle.forward(60)
turtle.setheading(0)
for i in range(4):
turtle.right(72)
turtle.forward(60)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行代码后,你会看到一个五星红旗的图案。注意,这只是一个基本的示例,你可以根据需要自行修改。
阅读全文