python画一颗漂亮的圣诞树
时间: 2023-12-26 11:28:28 浏览: 25
以下是使用Python绘制一颗漂亮的圣诞树的代码示例:
```python
import turtle as t
def draw_tree(trunk_length, branch_length, angle):
if branch_length < 5:
return
else:
t.forward(branch_length)
t.right(angle)
draw_tree(trunk_length, branch_length - 15, angle)
t.left(2 * angle)
draw_tree(trunk_length, branch_length - 15, angle)
t.right(angle)
t.backward(branch_length)
def draw_star():
t.penup()
t.goto(0, 200)
t.pendown()
t.color("yellow")
t.begin_fill()
for _ in range(5):
t.forward(50)
t.right(144)
t.end_fill()
def draw_trunk(trunk_length):
t.penup()
t.goto(-20, -200)
t.pendown()
t.color("brown")
t.begin_fill()
t.forward(40)
t.right(90)
t.forward(trunk_length)
t.right(90)
t.forward(40)
t.right(90)
t.forward(trunk_length)
t.end_fill()
def draw_christmas_tree():
t.speed("fastest")
t.bgcolor("black")
t.color("green")
t.penup()
t.goto(-100, -200)
t.pendown()
t.begin_fill()
t.left(90)
t.forward(200)
t.right(90)
draw_tree(50, 100, 30)
t.end_fill()
draw_star()
draw_trunk(80)
t.hideturtle()
t.done()
draw_christmas_tree()
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)