Python画五星红旗
时间: 2023-11-05 17:54:51 浏览: 55
以下是Python代码实现五星红旗的绘制:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(width=800, height=500)
turtle.bgcolor("red")
# 绘制大五角星
turtle.penup()
turtle.goto(-250, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
for i in range(5):
turtle.forward(120)
turtle.right(144)
turtle.end_fill()
# 绘制小五角星
turtle.penup()
turtle.goto(-100, 140)
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, 70)
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, 0)
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(-100, -70)
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.done()
```
运行上述代码,即可在窗口中看到绘制的五星红旗。
阅读全文