用代码画一颗圣诞树
作者:互联网
1 import turtle 2 import time 3 def draw(): 4 try: 5 screen = turtle.Screen() 6 screen.setup(700,700) 7 circle = turtle.Turtle() 8 circle.shape('circle') 9 circle.color('red') 10 circle.speed('fastest') 11 circle.up() 12 square = turtle.Turtle() 13 square.shape('square') 14 square.color('green') 15 square.speed('fastest') 16 square.up() 17 circle.goto(0,280) 18 circle.stamp() 19 k=0 20 for i in range(1,17): 21 y =30*i 22 for j in range(i - k): 23 x=30*j 24 square.goto(x, -y +280) 25 square.stamp() 26 square.goto(-x, -y +280) 27 square.stamp() 28 if i%4== 0: 29 x=30*(j+1) 30 circle.color('red') 31 circle.goto(-x, -y +280) 32 circle.stamp() 33 circle.goto(x,-y +280) 34 circle.stamp() 35 k+=3 36 if i% 4 == 3: 37 x =30*(j+1) 38 circle.color('yellow') 39 circle.goto(-x, -y +280) 40 circle.stamp() 41 circle.goto(x,-y +280) 42 circle. stamp() 43 square.color('brown') 44 for i in range(17,20): 45 y =30*i 46 for j in range(2): 47 x=30*j 48 square.goto(x,-y+280) 49 square. stamp() 50 square.goto(-x, -y +280) 51 square.stamp() 52 y=[30*i for i in [0,4,8,12,16]] 53 x1=[30*i for i in [0,3,4,5,6]] 54 x2=[30*i for i in [0,4,5,6,7]] 55 c=1 56 # yellow=[[60,90],[90,210],[120,330],[150,450]] 57 # red=[[120,120],[150,240],[180,360],[210,480]] 58 while(True): 59 if 1==c: 60 for i in range(5): 61 if not i == 0: 62 circle.color('red') 63 circle.goto(-x1[i], -y[i] + 310) 64 circle.stamp() 65 circle.goto(x1[i], -y[i] + 310) 66 circle.stamp() 67 circle.color('yellow') 68 circle.goto(-x2[i], -y[i] + 280) 69 circle.stamp() 70 circle.goto(x2[i], -y[i] + 280) 71 circle.stamp() 72 else: 73 for i in range(5): 74 if not i == 0: 75 circle.color('yellow') 76 circle.goto(-x1[i], -y[i] + 310) 77 circle.stamp() 78 circle.goto(x1[i], -y[i] + 310) 79 circle.stamp() 80 circle.color('red') 81 circle.goto(-x2[i], -y[i] + 280) 82 circle.stamp() 83 circle.goto(x2[i], -y[i] + 280) 84 circle.stamp() 85 86 c=c*-1 87 except: 88 exit() 89 90 91 def christmas_tree(): 92 draw() 93 if __name__ == '__main__': 94 christmas_tree()
标签:square,goto,stamp,代码,30,一颗,圣诞树,280,circle 来源: https://www.cnblogs.com/xancantcoding/p/15695036.html