大家好呀~
马上就是圣诞节了,先提前祝大家圣诞快乐!
今天来给大家分享一波如何使用 Python 来画一颗圣诞节树,包含多种版本,从平民版到豪华版,像极了一个程度员从入门到高级秃头程序员的过程。
本文涉及代码下载链接:https://docs.qq.com/doc/DU0lQRGFWbEtMd2Ro
部分代码(代码太多,有需要的找我)
import turtle
import time
screen = turtle.Screen()
screen.setup(800,600)
time.sleep(5)
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, 17):
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 += 2
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(17,20):
y = 30*i
for j in range(3):
x = 30*j
square.goto(x,-y+280)
square.stamp()
square.goto(-x,-y+280)
square.stamp()
turtle.exitonclick()
运行展示(部分圣诞树是有动态的,图片展示不出,友友们自己运行就能看出来啦)
咱们的基础款~小方格子,简单又有趣
吼吼吼~高级丝绒款!棉花糖一般的感觉,带有圣诞快乐的英文字祝福,伴随下雪的动作,更加的有氛围感,少女心满满啊~
超超超超超高级感~桌面圣诞树!!一棵不灵不灵发光闪闪五颜六色的圣诞树摆在桌面(可以很多很多棵哦~)
都拿去吧,愉快的过个圣诞节~ 祝大家圣诞节快乐!