python的turtle库画圣诞树
时间: 2023-11-30 17:43:25 浏览: 46
以下是使用Python的turtle库绘制圣诞树的代码和效果图:
```python
import turtle
# 设置画笔
t = turtle.Pen()
t.speed(0)
t.color("black")
# 绘制树干
t.penup()
t.goto(-50, -200)
t.pendown()
t.begin_fill()
t.setheading(90)
t.forward(100)
t.right(90)
t.forward(20)
t.right(90)
t.forward(100)
t.right(90)
t.forward(20)
t.end_fill()
# 绘制树叶
t.penup()
t.goto(-150, -100)
t.pendown()
t.color("green")
t.begin_fill()
t.setheading(0)
t.forward(300)
t.right(120)
t.forward(300)
t.right(120)
t.forward(300)
t.end_fill()
# 绘制装饰物
t.penup()
t.goto(-100, 0)
t.pendown()
t.color("red")
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(0, 50)
t.pendown()
t.color("yellow")
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(100, 0)
t.pendown()
t.color("red")
t.begin_fill()
t.circle(20)
t.end_fill()
# 显示窗口
turtle.done()
```
效果图如下:
![圣诞树](https://i.loli.net/2021/12/22/5JZz8vK6Q9q1j7L.png)
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)