Python用turtle画五星红旗
时间: 2023-11-16 21:45:13 浏览: 111
以下是Python使用turtle模块绘制五星红旗的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色和大小
turtle.color("red")
turtle.pensize(3)
# 绘制红旗
turtle.begin_fill()
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 绘制四个小星星
turtle.penup()
turtle.goto(-100, 175)
turtle.setheading(305)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-85, 125)
turtle.setheading(35)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-85, 70)
turtle.setheading(305)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 20)
turtle.setheading(35)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行以上代码将会在窗口中绘制出五星红旗的图案。
阅读全文