在这个画布上用python turtle绘制一个国旗
时间: 2024-05-18 19:16:41 浏览: 183
使用Python的turtle模块画国旗
好的,以下是绘制中国国旗的 Python 代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 画红色背景
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
for i in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-200, 120)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-80, 170)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 140)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-80, 70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(20)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
turtle.done()
```
运行代码后,会在窗口中绘制出中国国旗。注释中有详细的解释。
阅读全文