pycharm圣诞树代码
时间: 2023-12-18 11:30:09 浏览: 125
Python圣诞树代码
```python
import turtle
# 设置画布
win = turtle.Screen()
win.bgcolor("lightblue")
# 画树干
trunk = turtle.Turtle()
trunk.color("brown")
trunk.fillcolor("brown")
trunk.begin_fill()
trunk.left(90)
trunk.forward(100)
trunk.right(90)
trunk.backward(20)
trunk.right(90)
trunk.forward(40)
trunk.right(90)
trunk.backward(20)
trunk.end_fill()
# 画树叶
tree = turtle.Turtle()
tree.color("green")
tree.fillcolor("green")
tree.penup()
tree.goto(-50, 30)
tree.pendown()
tree.begin_fill()
tree.left(60)
tree.forward(100)
tree.left(120)
tree.forward(100)
tree.left(120)
tree.forward(100)
tree.end_fill()
# 画雪花
snow = turtle.Turtle()
snow.color("white")
snow.penup()
snow.goto(-200, 200)
snow.pendown()
snow.forward(50)
snow.backward(25)
snow.left(90)
snow.forward(25)
snow.backward(50)
snow.forward(25)
snow.right(90)
snow.forward(25)
snow.backward(50)
# 画小彩灯
lights = turtle.Turtle()
lights.color("red")
lights.penup()
lights.goto(-10, 10)
lights.dot(20, "red")
lights.goto(10, 10)
lights.dot(20, "yellow")
lights.goto(0, 20)
lights.dot(20, "blue")
# 画小礼物
gift = turtle.Turtle()
gift.color("red")
gift.fillcolor("red")
gift.penup()
gift.goto(-10, -50)
gift.pendown()
gift.begin_fill()
gift.forward(20)
gift.left(90)
gift.forward(20)
gift.left(90)
gift.forward(20)
gift.left(90)
gift.forward(20)
gift.left(90)
gift.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 关闭画布
win.mainloop()
```
阅读全文