![](https://img-blog.csdnimg.cn/526ac047915d46e9b0d4de8acc065a85.png)
圣诞节到了,给你最爱的人送上一棵python做的圣诞树吧。
程序员的专属浪漫。我的朋友圈已经让圣诞树刷屏了。
今天来给大家分享一波如何使用 Python 来画一颗圣诞节树,包含多种
版本,从平民版到豪华版
部分代码哦~
import turtle
screen = turtle.Screen()
screen.setup(375, 700)
circle = turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up()
square = turtle.Turtle()
square.shape('square')
square.color('green')
square.speed('fastest')
square.up()
circle.goto(0, 280)
circle.stamp()
k = 0
for i in range(1, 13):
y = 30 * i
for j in range(i - k):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
if i % 4 == 0:
x = 30 * (j + 1)
circle.color('red')
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
k += 3
if i % 4 == 3:
x = 30 * (j + 1)
circle.color('yellow')
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
square.color('brown')
for i in range(13, 17):
y = 30 * i
for j in range(2):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
基础款
![](https://img-blog.csdnimg.cn/b377f5c44a2643b387d159545639d287.png)
棉花糖款,棉花糖一般的感觉,带有圣诞快乐的英文字祝福,伴随下雪的动作,更加的有氛围感,少女心满满啊~
![](https://img-blog.csdnimg.cn/c3a8cf9754614215987d327e08d31c50.png)
桌面圣诞树!!一棵不灵不灵发光闪闪五颜六色的圣诞树摆在桌面(可以很多很多棵哦~)
漂亮的圣诞树,可作为桌面装饰哦~
效果图(这个是动态的):
![](https://img-blog.csdnimg.cn/b50f6339c61f4eaa9b983e83a4d7bbb8.png)
![](https://img-blog.csdnimg.cn/fb16c07daf1349268bcda0e0912b2491.png)