中国空间站

中国空间站

李兴球Python turtle中国空间站

要求绘制中国空间站的题目,我在很短的时间就做好了,就是那个APO算法大赛要求的。以下是我写的源代码:

import random
import turtle as t

screen = t.getscreen()
screen.delay(0)
screen.bgcolor('black')
t.colormode(255)
t.speed(0)
t.pencolor('white')
t.penup()
for _ in range(200):
    x = random.randint(-500,500)
    y = random.randint(-500,500)
    t.goto(x,y)
    t.dot(random.randint(2,5))
t.goto(0,0)    
t.setheading(0)
t.color('blue')
t.begin_fill()
t.circle(-40)
t.end_fill()
t.pu()
t.goto(-60,-20)
t.right(40)
t.pd()
t.pencolor('yellow')
t.pensize(3)
t.circle(200,40)
t.circle(4,160)
t.right(15)
t.circle(250,8)
t.pu()
t.circle(250,18)
t.pd()
t.circle(250,5)
t.circle(4,160)
t.pu()
t.goto(-60,-60)
t.pd()
for i in range(5):
   t.fd(15)
   t.right(144)
t.pu()
t.goto(40,-80)
t.pd()
t.seth(-45)
t.pensize(2)
for i in range(5):
   t.fd(10)
   t.right(144)
t.pu()
t.goto(-40,-100)
t.pd()
t.circle(5)
t.pu()
t.goto(-10,-90)
t.pd()
t.circle(2)
t.pu()
t.goto(40,-10)
t.pd()
t.circle(10)
t.pu()
t.goto(65,8)
t.pd()
t.circle(6)
t.pu()
t.goto(-10,5)
t.pd()
t.circle(5)
t.hideturtle()

t.pencolor('magenta')
all_xy = []
xy_0 =  [(-76, 55), (-41, 88), (10, 32), (-24, 1), (-76, 55), (0, 0, 255)]
xy_0 = [list(cc) for cc in xy_0]
xy_0 = [(cc[0],cc[1] +300) for cc in xy_0[:-1]] + [(0, 0, 255)]

xy_1 =  [(34, 3), (87, -50), (48, -83), (1, -30), (34, 3), (0, 0, 255)]
xy_1 = [list(cc) for cc in xy_1]
xy_1 = [( cc[0],cc[1] +300) for cc in xy_1[:-1]]+  [(0, 0, 255)]

xy_2 =  [(27, 46), (42, 42), (50, 32), (53, 21), (-3, -29), (-3, -37), (-55, -84), (-67, -84), (-77, -79), (-83, -72), (-86, -55), (-80, -44), (-36, -4), (-24, -5), (27, 46), (192, 192, 192)]
xy_2 = [list(cc) for cc in xy_2]
xy_2 = [(cc[0],cc[1] +300) for cc in xy_2[:-1]]+  [(192, 192, 192)]

xy_3 =  [(-62, -29), (-30, -60), (-41, -70), (-74, -39), (-62, -29), (128, 64, 0)]
xy_3 = [list(cc) for cc in xy_3]
xy_3 = [(cc[0],cc[1] +300) for cc in xy_3[:-1]]+ [(128, 64, 0)]

xy_4 =  [(-40, -36), (-25, -20), (-15, -29), (-30, -46), (-40, -36), (255, 0, 0)]
xy_4 = [list(cc) for cc in xy_4]
xy_4 = [(cc[0],cc[1]+300) for cc in xy_4[:-1]] + [(0, 0, 255)]


all_xy.append(xy_0)
all_xy.append(xy_1)
all_xy.append(xy_2)
all_xy.append(xy_3)
all_xy.append(xy_4)

k = 2
for cors in all_xy:
    t.penup()
    x,y = cors[0]
    t.goto(x/k,y/k)
    t.pendown()
    if cors[-1]!='':
       t.fillcolor(cors[-1])
       t.begin_fill()
    for x,y in cors[1:-1]:
        t.goto(x/k,y/k)
    if cors[-1]!='':    
       t.end_fill()
        
t.pencolor('white')
t.penup()
t.goto(0,70)
t.write('中国空间站 ',align='center',font=('arail',26,'normal'))
    
t.done()

李兴球

李兴球的博客是Python创意编程原创博客