Python画五星红旗
时间: 2023-11-05 17:54:51 浏览: 32
以下是使用Python的Turtle库画五星红旗的代码:
```
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔宽度
turtle.pensize(3)
# 隐藏画笔
turtle.hideturtle()
# 绘制红色矩形
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(-150, 100)
turtle.setheading(0)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.right(18)
for i in range(5):
turtle.forward(300)
turtle.right(144)
turtle.end_fill()
# 绘制四个小五角星
turtle.penup()
turtle.goto(-90, 170)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.right(18)
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 140)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.right(18)
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 70)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.right(18)
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-90, 40)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.right(18)
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
# 点击关闭窗口
turtle.exitonclick()
```
运行代码,即可在窗口中看到绘制的五星红旗。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)