Python画五星红旗
时间: 2023-11-05 15:56:23 浏览: 207
以下是使用Python Turtle库画五星红旗的代码:
```python
import turtle
# 设置画布和画笔
screen = turtle.Screen()
pen = turtle.Turtle()
pen.speed(5)
pen.hideturtle()
# 画大红底
pen.penup()
pen.goto(-300, 200)
pen.pendown()
pen.color("red")
pen.begin_fill()
for i in range(2):
pen.forward(600)
pen.right(90)
pen.forward(400)
pen.right(90)
pen.end_fill()
# 画大星星
pen.penup()
pen.goto(-200, 120)
pen.pendown()
pen.color("yellow")
pen.begin_fill()
for i in range(5):
pen.forward(80)
pen.right(144)
pen.end_fill()
# 画四个小星星
star_pos = [(-100, 170), (-80, 70), (-100, 20), (-160, 70)]
for pos in star_pos:
pen.penup()
pen.goto(pos)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(25)
pen.right(144)
pen.end_fill()
# 结束
screen.mainloop()
```
运行代码后,会在画布上绘制出五星红旗的图案。
阅读全文