python的turtle库画圣诞树
时间: 2023-11-30 16:43:25 浏览: 99
以下是使用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()
```
效果图如下:

阅读全文
相关推荐










