python画五星红旗
时间: 2023-10-10 09:12:34 浏览: 81
以下是Python代码,用turtle库绘制五星红旗:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.setup(600, 400)
pen = turtle.Turtle()
pen.speed(10)
# 绘制红色背景
pen.penup()
pen.goto(-200, 150)
pen.pendown()
pen.color("red")
pen.begin_fill()
for i in range(2):
pen.forward(400)
pen.right(90)
pen.forward(250)
pen.right(90)
pen.end_fill()
# 绘制大五角星
pen.penup()
pen.goto(-120, 90)
pen.pendown()
pen.color("yellow")
pen.begin_fill()
for i in range(5):
pen.forward(120)
pen.right(144)
pen.end_fill()
# 绘制四个小五角星
pen.penup()
pen.goto(-50, 120)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(30)
pen.right(144)
pen.end_fill()
pen.penup()
pen.goto(-30, 70)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(30)
pen.right(144)
pen.end_fill()
pen.penup()
pen.goto(-50, 20)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(30)
pen.right(144)
pen.end_fill()
pen.penup()
pen.goto(-90, 70)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(30)
pen.right(144)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
turtle.done()
```
运行代码后,会在屏幕上显示出五星红旗的图案。如下图所示:
![五星红旗](https://img-blog.csdnimg.cn/20210701171458624.png)
阅读全文