使用turtle库绘制树五星红旗
时间: 2023-11-01 17:08:31 浏览: 80
使用Python的turtle模块画国旗
以下是使用turtle库绘制树五星红旗的Python代码:
```python
import turtle
# 设置画笔大小和颜色
turtle.pensize(3)
turtle.pencolor("red")
# 绘制红旗
turtle.begin_fill()
turtle.forward(300)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(300)
turtle.end_fill()
# 移动画笔到左上角
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
# 绘制大五角星
turtle.begin_fill()
for i in range(5):
turtle.forward(120)
turtle.right(144)
turtle.end_fill()
# 移动画笔到左上角
turtle.penup()
turtle.goto(-90, 120)
turtle.pendown()
# 绘制小五角星
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 移动画笔到右上角
turtle.penup()
turtle.goto(60, 120)
turtle.pendown()
# 绘制小五角星
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 移动画笔到左下角
turtle.penup()
turtle.goto(-90, -20)
turtle.pendown()
# 绘制小五角星
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 移动画笔到右下角
turtle.penup()
turtle.goto(60, -20)
turtle.pendown()
# 绘制小五角星
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,将会看到一个使用turtle库绘制的树五星红旗。
阅读全文