用python画出五星红旗
时间: 2023-11-19 13:43:41 浏览: 104
以下是使用 Python 中的 turtle 库绘制五星红旗的代码:
```python
import turtle
# 设置画笔
t = turtle.Pen()
t.speed(0)
t.hideturtle()
# 绘制背景矩形
t.penup()
t.goto(-250, 150)
t.pendown()
t.begin_fill()
t.fillcolor("#DE2910")
for i in range(2):
t.fd(500)
t.right(90)
t.fd(300)
t.right(90)
t.end_fill()
# 绘制大星星
t.penup()
t.goto(-200, 100)
t.pendown()
t.begin_fill()
t.fillcolor("#FDFD96")
t.right(75)
for i in range(5):
t.fd(80)
t.right(144)
t.end_fill()
# 绘制四个小星星
t.penup()
t.goto(-70, 80)
t.pendown()
t.begin_fill()
t.fillcolor("#FDFD96")
t.right(75)
for i in range(5):
t.fd(30)
t.right(144)
t.end_fill()
t.penup()
t.goto(-40, 50)
t.pendown()
t.begin_fill()
t.fillcolor("#FDFD96")
t.right(75)
for i in range(5):
t.fd(30)
t.right(144)
t.end_fill()
t.penup()
t.goto(-70, 20)
t.pendown()
t.begin_fill()
t.fillcolor("#FDFD96")
t.right(75)
for i in range(5):
t.fd(30)
t.right(144)
t.end_fill()
t.penup()
t.goto(-100, 50)
t.pendown()
t.begin_fill()
t.fillcolor("#FDFD96")
t.right(75)
for i in range(5):
t.fd(30)
t.right(144)
t.end_fill()
# 显示绘图窗口
turtle.done()
```
运行以上代码,即可在窗口中看到绘制的五星红旗。
阅读全文
相关推荐














