Python画五星红旗
时间: 2023-11-05 22:57:24 浏览: 15
您可以使用Python的turtle库来绘制五星红旗。以下是示例代码:
```python
import turtle
# 画红色矩形
turtle.fillcolor('red')
turtle.begin_fill()
turtle.fd(400)
turtle.left(90)
turtle.fd(280)
turtle.left(90)
turtle.fd(400)
turtle.left(90)
turtle.fd(280)
turtle.left(90)
turtle.end_fill()
# 画大星星
turtle.pensize(3)
turtle.penup()
turtle.goto(-120, 100)
turtle.pendown()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.forward(60)
turtle.right(72)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-70, 50)
turtle.setheading(305)
turtle.pendown()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.forward(30)
turtle.right(72)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-70, 20)
turtle.setheading(10)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.forward(30)
turtle.right(72)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-120, -20)
turtle.setheading(35)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.forward(30)
turtle.right(72)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-45, -20)
turtle.setheading(55)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(30)
turtle.right(144)
turtle.forward(30)
turtle.right(72)
turtle.end_fill()
turtle.done()
```
运行上述代码即可在窗口中看到五星红旗的绘制结果。
相关推荐
![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)
![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)