turtle画五星红旗
时间: 2023-10-10 07:13:50 浏览: 275
以下是使用Python中的turtle库绘制五星红旗的代码:
```
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor('#DE2910')
# 绘制大五角星
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(300)
turtle.right(144)
turtle.end_fill()
# 绘制四个小五角星
turtle.penup()
turtle.goto(-90, 180)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 70)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 70)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(90, 180)
turtle.pendown()
turtle.begin_fill()
for _ in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔,完成绘制
turtle.hideturtle()
turtle.done()
```
运行以上代码,即可在turtle画布上绘制出五星红旗。
阅读全文