用Python编写国旗代码
时间: 2023-11-16 22:48:47 浏览: 113
好的,以下是用 Python 编写的中国国旗代码:
```python
import turtle
# 设置国旗宽度和高度
WIDTH = 600
HEIGHT = 400
# 设置红色背景
turtle.penup()
turtle.goto(-WIDTH/2, HEIGHT/2)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
turtle.forward(WIDTH)
turtle.right(90)
turtle.forward(HEIGHT)
turtle.right(90)
turtle.forward(WIDTH)
turtle.right(90)
turtle.forward(HEIGHT)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-WIDTH/6, HEIGHT/6)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画小星星1
turtle.penup()
turtle.goto(WIDTH/10, HEIGHT/3)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星2
turtle.penup()
turtle.goto(-WIDTH/10, HEIGHT/5)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星3
turtle.penup()
turtle.goto(-WIDTH/10, -HEIGHT/5)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 画小星星4
turtle.penup()
turtle.goto(WIDTH/10, -HEIGHT/3)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
请留意,这只是一个简单的 Python 代码,可能还有很多细节可以优化。
阅读全文