用python画一个五星红旗
时间: 2023-10-10 11:11:43 浏览: 146
python 实现五星红旗源码
好的,下面是使用Python中的turtle库绘制五星红旗的代码示例:
```python
import turtle
#创建画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(10)
pen.hideturtle()
# 绘制红色矩形
pen.penup()
pen.goto(-250, 150)
pen.pendown()
pen.begin_fill()
pen.color("red")
for i in range(2):
pen.forward(500)
pen.right(90)
pen.forward(300)
pen.right(90)
pen.end_fill()
# 绘制大星星
pen.penup()
pen.goto(-200, 100)
pen.pendown()
pen.begin_fill()
pen.color("yellow")
for i in range(5):
pen.forward(80)
pen.right(144)
pen.end_fill()
# 绘制四个小星星
positions = [(60, 160), (-60, 160), (60, 40), (-60, 40)]
for x, y in positions:
pen.penup()
pen.goto(x, y)
pen.pendown()
pen.begin_fill()
pen.color("yellow")
for i in range(5):
pen.forward(20)
pen.right(144)
pen.end_fill()
# 显示画布
canvas.mainloop()
```
运行代码后,就可以在画布上看到绘制的五星红旗了!
阅读全文