国旗迎风飘扬的Python代码
时间: 2024-06-01 14:06:05 浏览: 120
你可以使用Python的turtle模块来绘制一个国旗迎风飘扬的效果。以下是一个示例代码:
```python
import turtle
# 设置画笔的颜色和填充颜色
turtle.pencolor('red')
turtle.fillcolor('red')
# 绘制矩形
turtle.begin_fill()
turtle.goto(200, 0)
turtle.goto(200, 100)
turtle.goto(0, 100)
turtle.goto(0, 0)
turtle.end_fill()
# 绘制五角星
turtle.penup()
turtle.goto(30, 70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制五角星
turtle.penup()
turtle.goto(70, 50)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制五角星
turtle.penup()
turtle.goto(70, 10)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制五角星
turtle.penup()
turtle.goto(30, -10)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 绘制五角星
turtle.penup()
turtle.goto(100, -10)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
你可以运行这段代码,就可以看到绘制出来的国旗了。
阅读全文