python画图代码圣诞树
时间: 2023-09-26 12:11:38 浏览: 66
好的,以下是一个简单的 Python 代码来画一棵圣诞树:
```
# 导入必要的库
import turtle
# 初始化窗口
window = turtle.Screen()
window.bgcolor("white")
window.title("A Christmas Tree")
# 设置画笔
pen = turtle.Turtle()
pen.speed(0)
pen.color("green")
pen.penup()
pen.goto(0, -200)
pen.pendown()
# 画圣诞树的三角形部分
def draw_triangle(length, angle):
pen.forward(length)
pen.right(angle)
pen.forward(length)
pen.right(180-angle)
pen.forward(length)
pen.right(angle)
pen.forward(length)
pen.begin_fill()
draw_triangle(100, 75)
pen.end_fill()
pen.begin_fill()
draw_triangle(75, 75)
pen.end_fill()
pen.begin_fill()
draw_triangle(50, 75)
pen.end_fill()
# 绘制树干
pen.color("brown")
pen.right(90)
pen.forward(50)
pen.right(180)
pen.forward(50)
# 等待退出
window.exitonclick()
```
希望这可以帮到你。
阅读全文