用turtle画五星红旗
时间: 2023-10-10 16:14:44 浏览: 38
以下是使用Python中的Turtle模块绘制五星红旗的代码:
```python
import turtle
# 设置画布大小和画笔速度
turtle.setup(800, 600)
turtle.speed(0)
# 绘制红色背景
turtle.penup()
turtle.goto(-400, 300)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
for i in range(2):
turtle.forward(800)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-200, 170)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.right(72)
for i in range(5):
turtle.forward(120)
turtle.right(144)
turtle.end_fill()
# 绘制小星星1
turtle.penup()
turtle.goto(-120, 270)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.right(162)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制小星星2
turtle.penup()
turtle.goto(-100, 200)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.right(162)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制小星星3
turtle.penup()
turtle.goto(-120, 130)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.right(162)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制小星星4
turtle.penup()
turtle.goto(-200, 110)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.right(162)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行代码后,即可在窗口中看到绘制好的五星红旗。
阅读全文