Python绘制五星红旗
时间: 2023-11-05 16:57:25 浏览: 478
可以使用Python的turtle库来绘制五星红旗。以下是实现代码:
```Python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 画五星旗
def drawFlag():
# 画红色矩形
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
for i in range(2):
turtle.forward(500)
turtle.right(90)
turtle.forward(300)
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(80)
turtle.right(144)
turtle.end_fill()
# 画四个小星星
turtle.penup()
turtle.goto(-60, 170)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 40)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-120, 80)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 调用绘制函数
drawFlag()
turtle.done()
```
运行代码后,就可以看到绘制的五星红旗啦!
阅读全文