如何使用python画国旗
时间: 2023-09-29 15:05:52 浏览: 224
以下是使用 Python 画中国国旗的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 400)
turtle.bgcolor('red')
# 画大五角星
turtle.penup()
turtle.goto(-250, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画四个小五角星
turtle.penup()
turtle.goto(-120, 130)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for _ in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 70)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for _ in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 100)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for _ in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 40)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
for _ in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
执行上述代码,即可在绘图窗口中看到绘制好的中国国旗。
阅读全文
相关推荐














