圣诞节就要到了——快用python安排几棵圣诞树吧~

 大家好呀~

马上就是圣诞节了,先提前祝大家圣诞快乐!

今天来给大家分享一波如何使用 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()


运行展示(部分圣诞树是有动态的,图片展示不出,友友们自己运行就能看出来啦)

 咱们的基础款~小方格子,简单又有趣

 

吼吼吼~高级丝绒款!棉花糖一般的感觉,带有圣诞快乐的英文字祝福,伴随下雪的动作,更加的有氛围感,少女心满满啊~

 

超超超超超高级感~桌面圣诞树!!一棵不灵不灵发光闪闪五颜六色的圣诞树摆在桌面(可以很多很多棵哦~)

 都拿去吧,愉快的过个圣诞节~  祝大家圣诞节快乐!

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值