Python绘图五星红旗
时间: 2023-11-05 18:51:29 浏览: 90
下面是使用Python的turtle库绘制五星红旗的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔粗细
turtle.pensize(3)
# 隐藏画笔
turtle.hideturtle()
# 绘制红色矩形
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('#FF0000')
for i in range(2):
turtle.forward(480)
turtle.right(90)
turtle.forward(320)
turtle.right(90)
turtle.end_fill()
# 绘制大五角星
turtle.penup()
turtle.goto(-150, 100)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('#FFFF00')
turtle.right(18)
for i in range(5):
turtle.forward(120)
turtle.right(144)
turtle.end_fill()
# 绘制四个小五角星
positions = [(20, 170), (70, 140), (70, 70), (20, 40)]
turtle.penup()
for pos in positions:
turtle.goto(pos)
turtle.setheading(0)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('#FFFF00')
turtle.right(72)
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.end_fill()
# 显示结果
turtle.done()
```
运行上述代码,即可得到五星红旗的图像。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)