python五星红旗代码
时间: 2024-04-14 14:22:50 浏览: 228
python项目实例代码源码-五星红旗.zip
Python五星红旗代码是指使用Python编程语言绘制中国国旗的代码。下面是一个简单的示例代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔速度
turtle.speed(10)
# 绘制红色背景
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("red")
for _ in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 绘制大星星
turtle.penup()
turtle.goto(-180, 120)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("yellow")
for _ in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
# 绘制四颗小星星
positions = [(-60, 180), (-30, 150), (-30, 210), (0, 180)]
for position in positions:
turtle.penup()
turtle.goto(position)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("yellow")
for _ in range(5):
turtle.forward(12)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口退出程序
turtle.exitonclick()
```
阅读全文