反正也没什么人看,搞个圣诞树

本文通过Python代码绘制了一棵精美的圣诞树,并在圣诞前夕送上祝福。代码详细展示了如何使用turtle模块创建图形,包括圣诞树、苹果、蝴蝶结、星星等元素,同时还模拟了动态飘落的雪花。此外,文章还包含了对考研学子的鼓励,以及对2021年即将结束的感慨和对未来的美好祝愿。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

​今晚的平安夜,明天的圣诞节,祝大家平安夜开心,圣诞节快乐,祝明天考研的学子考神附体,Merry Christmas!

2021即将走进尾声,愿你喜欢的都拥有,失去的都释怀,祝你平安喜乐,心想事成

在这里插入图片描述

先来看看圣诞树效果吧

在这里插入图片描述

在这里插入图片描述

画苹果

goto(0, 150)
turtle.begin_fill()
turtle.color("red")
turtle.circle(radius=30)
turtle.end_fill()

turtle.color("brown")
turtle.pu()
turtle.goto(-15, 190)
turtle.pd()
turtle.circle(36, 40)
turtle.pu()
turtle.seth(105)
turtle.goto(-1, 194)
turtle.pd()
turtle.circle(36, 50)
turtle.pd()
​

turtle.begin_fill()
turtle.color("green")
turtle.circle(36, 50)
turtle.seth(-30)
turtle.circle(36, 55)
turtle.end_fill()
​
turtle.begin_fill()
turtle.color("green")
turtle.seth(0)
turtle.circle(36, 50)
turtle.seth(-180)
turtle.circle(36, 50)
turtle.end_fill()
penup()

在这里插入图片描述

画圣诞树

seth(-120)
for i in range(10):
    fd(12)
    right(2)
penup()
goto(0, 150)
seth(-60)
pendown()
for i in range(10):
    fd(12)
    left(2)
seth(-150)
penup()
fd(10)
pendown()
for i in range(5):
    fd(10)
    right(15)
seth(-150)
penup()
fd(8)
pendown()
for i in range(5):
    fd(10)
    right(15)
seth(-155)
penup()
fd(5)
pendown()
for i in range(5):
    fd(7)
    right(15)

penup()
goto(-55, 34)
pendown()
seth(-120)
for i in range(10):
    fd(8)
    right(5)
​
penup()
goto(50, 35)
seth(-60)
pendown()
for i in range(10):
    fd(8)
    left(5)
seth(-120)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
    fd(10)
    right(15)
penup()
fd(10)
seth(-145)
pendown()
for i in range(5):
    fd(12)
    right(15)
penup()
fd(8)
seth(-145)
pendown()
for i in range(5):
    fd(10)
    right(15)
penup()
seth(-155)
fd(8)
pendown()
for i in range(5):
    fd(11)
    right(15)

penup()
goto(-100, -40)
seth(-120)
pendown()
for i in range(10):
    fd(6)
    right(3)
penup()
goto(80, -39)
seth(-50)
pendown()
for i in range(10):
    fd(6)
    left(3)
seth(-155)
penup()
fd(10)
pendown()
for i in range(5):
    fd(8)
    right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
    fd(8)
    right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
    fd(7)
    right(10)
penup()
fd(8)
seth(-145)
pendown()
for i in range(7):
    fd(7)
    right(10)
penup()
fd(8)
seth(-140)
pendown()
for i in range(7):
    fd(6)
    right(10)
​

penup()
goto(-120, -95)
seth(-130)
pendown()
for i in range(7):
    fd(10)
    right(5)
penup()
goto(100, -95)
seth(-50)
pendown()
for i in range(7):
    fd(10)
    left(5)
penup()
seth(-120)
fd(10)
seth(-155)
pendown()
for i in range(6):
    fd(8)
    right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
    fd(8)
    right(10)
penup()
seth(-160)
fd(10)
seth(-155)
pendown()
for i in range(6):
    fd(8)
    right(10)
penup()
seth(-160)
fd(10)
seth(-160)
pendown()
for i in range(6):
    fd(8)
    right(10)
penup()
seth(-160)
fd(10)
seth(-160)
pendown()
for i in range(6):
    fd(8)
    right(10)
penup()
seth(-160)
fd(10)
seth(-165)
pendown()
for i in range(5):
    fd(10)
    right(11)

画树干

pencolor("#8B4513")
penup()
goto(-70, -165)
seth(-85)
pendown()
for i in range(3):
    fd(5)
    left(3)
penup()
goto(70, -165)
seth(-95)
pendown()
for i in range(3):
    fd(5)
    right(3)
seth(-170)
penup()
fd(10)
pendown()
pendown()
for i in range(10):
    fd(12)
    right(2)

在这里插入图片描述

画蝴蝶结

def hdj(x, y):
   
    penup()
    pencolor("#f799e6")
    goto(x, y)
    seth(80)
    pendown()
    pensize(2)
    circle(5)
    seth(10)
    fd(15)
    seth(120)
    fd(20)
    seth(240)
    fd(20)
    seth(180)
    fd(20)
    seth(-60)
    fd(20)
    seth(50)
    fd(20)
    seth(-40)
    fd(30)
    seth(-130)
    fd(5)
    seth(135)
    fd(30)
    seth(-60)
    fd(30)
    seth(-150)
    fd(6)
    seth(110)
    fd(30)
​
​
def uit(x, y):
   
    penup()
    pencolor("#f799e6")
    goto(x, y)
    pendown()
    pensize(2)
    circle(5)
    seth(-10)
    fd(15)
    seth(90)
    fd(15)
    seth(200)
    fd(15)
    seth(160)
    fd(15)
    seth(-90)
    fd(15)
    seth(10)
    fd(15)
    seth(-60)
    fd(20)
    seth(-180)
    fd(5)
    seth(110)
    fd(20)
    seth(-90)
    fd(20)
    seth(-180)
    fd(6)
    seth(70)
    fd(15)
    hideturtle()
    
seth(0)
uit(40, -150)
​
hdj(-80, -110)
yut(-67, -105, 120)
yut(-86, -113, 150)
​
hdj(40, -40)
yut(52, -35, 130)
yut(34, -45, 160)
seth(0)
uit(-20, -50)
yut(-4, -50, 100)
yut(-20, -50, 120)
​
hdj(-30, 30)
yut(-15, 35, 130)
yut(-40, 30, 180)
​
uit(30, 70)
yut(45, 70, 100)
yut(30, 70, 120)
​
​
def iou(x, y, z):
    penup()
    goto(x, y)
    pencolor("red")
    pendown()
    seth(z)
    for po in range(10):
        fd(4)
        left(18)


seth(-20)
pensize(2)
penup()
goto(-30, -120)
pencolor("white")
pendown()
fillcolor("white")
begin_fill()
fd(30)
circle(4, 180)
fd(30)
circle(4, 180)
end_fill()
penup()
goto(-25, -115)
seth(75)
pendown()
fillcolor("red")
begin_fill()
for i in range(5):
    fd(6)
    right(20)
seth(-10)
for i in range(5):
    fd(8)
    right(15)
seth(145)
for i in range(5):
    fd(5)
    left(2)
seth(90)
for i in range(5):
    fd(1)
    left(2)
seth(-90)
for i in range(4):
    fd(4)
    right(6)
seth(161)
fd(30)
end_fill()
pensize(1)
pencolor("white")


def koc(x, y, size):
    pensize(2)
    pencolor("yellow")
    penup()
    goto(x, y)
    pendown()
    begin_fill()
    fillcolor("yellow")
    for i in range(5):
        left(72)
        fd(size)
        right(144)
        fd(size)
    end_fill()


在这里插入图片描述

画星星

seth(-15)
koc(-120, -70, 10)
seth(10)
koc(100, -20, 10)
seth(-10)
koc(10, 40, 10)
seth(30)
koc(-80, 60, 10)
koc(100, -150, 10)
koc(-140, -150, 10)
koc(80, -100, 10)



def koc(x, y, size):
    pensize(2)
    pencolor("yellow")
    penup()
    goto(x, y)
    pendown()
    begin_fill()
    fillcolor("yellow")
    for i in range(5):
        left(72)
        fd(size)
        right(144)
        fd(size)
    end_fill()
​
​

seth(-15)
koc(-120, -70, 10)
seth(10)
koc(100, -20, 10)
seth(-10)
koc(10, 40, 10)
seth(30)
koc(-80, 60, 10)
koc(100, -150, 10)
koc(-140, -150, 10)
koc(80, -100, 10)

在这里插入图片描述

画动态雪花

screen.delay(0)  
t = Turtle(visible=False, shape='circle')
t.pencolor("white")
t.fillcolor("white")
t.penup()
t.setheading(-90)
t.goto(r.randint(-width / 2, width / 2), height / 2)
stars = []
for i in range(200):
    star = t.clone()
    s = r.random() / 3
    star.shapesize(s, s)
    star.speed(int(s * 10))
    star.setx(r.randint(-width / 2, width / 2))
    star.sety(height / 2 + r.randint(1, height))
    star.showturtle()
    stars.append(star)
while True:
    for star in stars:
        star.sety(star.ycor() - 8 * star.speed())
        if star.ycor() < -height / 2:
            star.hideturtle()
            star.setx(r.randint(-width / 2, width / 2))
            star.sety(height / 2 + r.randint(1, height))
            star.showturtle()
​
hideturtle()
done()

感性与理性的交织,迷茫与坚定的纵横,业余与专业的并行,追梦我伴你前行

源码可到"一团追梦喵"发送"圣诞树"即可,发送"玫瑰花",也会有惊喜呦!

悄悄告诉你们,小编的圣诞祝福是看到这段话的宝贝:暴富,恋爱,平安,幸福。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

织雪成纱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值