用turtle画五星红旗
时间: 2023-10-10 22:14:44 浏览: 89
好的,以下是用Python的turtle库绘制五星红旗的代码:
```python
import turtle
# 设置画笔大小和速度
turtle.pensize(3)
turtle.speed(10)
# 绘制红色矩形
turtle.color("red")
turtle.begin_fill()
turtle.forward(400)
turtle.right(90)
turtle.forward(280)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(280)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-120, 100)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 绘制小星星1
turtle.penup()
turtle.goto(-40, 175)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 绘制小星星2
turtle.penup()
turtle.goto(-40, 70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 绘制小星星3
turtle.penup()
turtle.goto(50, 175)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 绘制小星星4
turtle.penup()
turtle.goto(50, 70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行上述代码即可在窗口中看到绘制的五星红旗。
阅读全文