圣诞节快到了,最近圣诞树的绘制图比较火热,也很漂亮,今天我就整理了一下源码,分享给大家(这些我都测试过,确实可以生成喔~)
动态生成圣诞树
效果图(这个是动态的):
漂亮的圣诞树,可作为桌面装饰哦~
import turtlescreen = 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 * ifor j in range(i - k):x = 30 * jsquare.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 += 3if 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 * ifor j in range(2):x = 30 * jsquare.goto(x, -y + 280)square.stamp()square.goto(-x, -y + 280)square.stamp()
代码打包了
备注 “圣诞树”腾讯文档-在线文档https://docs.qq.com/doc/DRlZZSVVWaG1GeURi