用turtle画五星红旗
时间: 2023-10-10 11:13:48 浏览: 51
以下是使用Python中的turtle库来绘制五星红旗的示例代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 隐藏画笔
turtle.hideturtle()
# 画红色背景
turtle.penup()
turtle.goto(-350, 250)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.forward(700)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(700)
turtle.right(90)
turtle.forward(500)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-200, 180)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画四个小星星
turtle.penup()
turtle.goto(-120, 90)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 130)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, 90)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 点击窗口关闭程序
turtle.exitonclick()
```
运行代码后,程序将在屏幕上绘制出五星红旗。你可以根据需要调整绘制的大小和位置。
相关推荐
![](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)
![](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)