Python绘制圣诞树

import turtle

# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#008080")

# 定义一个函数来绘制树杈
def branch(length, level):
    if level == 0:
        # 到达最后一层,绘制树叶
        turtle.color("#008000")
        turtle.begin_fill()
        turtle.circle(10)
        turtle.end_fill()
    else:
        # 绘制树枝
        turtle.pensize(level)
        turtle.color("#8B4513")
        turtle.forward(length)
        turtle.right(30)
        branch(length * 0.8, level - 1)
        turtle.left(60)
        branch(length * 0.8, level - 1)
        turtle.right(30)
        turtle.backward(length)

# 绘制树干
turtle.color("#8B4513")
turtle.pensize(20)
turtle.penup()
turtle.goto(0, -250)
turtle.pendown()
turtle.goto(0, -50)

# 绘制树杈
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
branch(100, 4)

# 绘制树底
turtle.color("#8B4513")
turtle.begin_fill()
turtle.penup()
turtle.goto(-150, -250)
turtle.pendown()
turtle.goto(150, -250)
turtle.goto(0, -300)
turtle.end_fill()

# 绘制星星
turtle.color("#FFFF00")
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
    turtle.forward(20)
    turtle.right(144)
turtle.end_fill()

turtle.done()
 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值