turtle画五星红旗
时间: 2023-10-10 16:13:50 浏览: 89
python turtle 画国标 国旗 五星红旗 旗面高度可变
以下是使用Python中的turtle模块画五星红旗的代码:
```python
import turtle
# 设置画笔颜色和填充颜色
turtle.pencolor("red")
turtle.fillcolor("red")
# 绘制红旗
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.pencolor("yellow")
turtle.fillcolor("yellow")
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 绘制四个小星星
turtle.penup()
turtle.goto(-50, 180)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 80)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-220, 180)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-220, 80)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.hideturtle() # 隐藏画笔
turtle.done() # 完成绘制
```
运行代码后,就可以在窗口中看到绘制出来的五星红旗啦!
阅读全文