pycharm圣诞树
时间: 2023-12-25 11:30:14 浏览: 99
以下是使用turtle库在PyCharm中绘制圣诞树的代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("black")
# 创建画笔
pen = turtle.Turtle()
pen.speed(10)
pen.color("green")
# 绘制树干
pen.penup()
pen.goto(-50, -200)
pen.pendown()
pen.begin_fill()
pen.goto(50, -200)
pen.goto(50, -150)
pen.goto(-50, -150)
pen.goto(-50, -200)
pen.end_fill()
# 绘制树叶
pen.penup()
pen.goto(-200, -150)
pen.pendown()
pen.color("green")
pen.begin_fill()
pen.goto(0, 100)
pen.goto(200, -150)
pen.goto(-200, -150)
pen.end_fill()
# 绘制圣诞节礼物
pen.penup()
pen.goto(-100, -200)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.goto(-100, -100)
pen.goto(100, -100)
pen.goto(100, -200)
pen.goto(-100, -200)
pen.end_fill()
# 绘制圣诞节礼物的蝴蝶结
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.color("yellow")
pen.begin_fill()
pen.goto(-100, 0)
pen.goto(0, 50)
pen.goto(100, 0)
pen.goto(100, -100)
pen.goto(-100, -100)
pen.end_fill()
# 绘制圣诞节礼物的蝴蝶结上的小圆圈
pen.penup()
pen.goto(-50, 0)
pen.pendown()
pen.color("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 结束绘制
turtle.done()
```
阅读全文