python绘画五星红旗
时间: 2023-11-20 08:55:53 浏览: 131
以下是使用Python绘制五星红旗的代码:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 定义绘制五角星的函数
def draw_star(radius, color):
angle = 144
turtle.fillcolor(color)
turtle.begin_fill()
for side in range(5):
turtle.forward(radius)
turtle.right(angle)
turtle.forward(radius)
turtle.right(72 - angle)
turtle.end_fill()
# 绘制红色背景
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 绘制大五角星
turtle.penup()
turtle.goto(-200, 120)
turtle.pendown()
draw_star(100, 'yellow')
# 绘制四个小五角星
turtle.penup()
turtle.goto(-70, 170)
turtle.pendown()
draw_star(40, 'yellow')
turtle.penup()
turtle.goto(-40, 70)
turtle.pendown()
draw_star(40, 'yellow')
turtle.penup()
turtle.goto(-70, -30)
turtle.pendown()
draw_star(40, 'yellow')
turtle.penup()
turtle.goto(-160, 70)
turtle.pendown()
draw_star(40, 'yellow')
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
阅读全文