# 用 Phython 展示太阳系的运动模型

1，sun

``````# init the Solar System Icons
``````

2，sky

``````# draw sky
def draw_sky(sw_init):

if sw_init:
sw_init = False
for i in range(1,50,1):
rand_x = random.randint(1,790)
rand_y = random.randint(1,790)
star = [rand_x, rand_y]
stars.append( star )
else:
# draw Sun
playgd.blit( ico_solar, [pos_sun[0]-50,pos_sun[1]-50] )

for star in stars :
pygame.draw.rect( playgd, [255,255,255],[star[0],star[1],2,2],1 )
``````

3，planet

``````class planet_m(pygame.sprite.Sprite):
def __init__(self, img, loc, radius, spd ):
pygame.sprite.Sprite.__init__(self)
self.rect = self.image.get_rect()
self.pos = loc
self.speed = spd
self.angle = 0
print( "p_x="+str(self.pos[0])+";p_y="+str(self.pos[1]) )
self.rect = self.rect.move( self.pos )

def move( self ):

self.angle += self.speed
#print( "angle="+str(self.angle)+"; delt_x="+str(delt_x)+", delt_y="+str(delt_y) )
self.rect = self.rect.move( [ -delt_x, delt_y])
``````

4，planet circle

``````    # draw tracks & planets
for i in range(1,7,1):
pygame.draw.circle( playgd, [50,50,50],pos_sun, 50+50*i,2 )
``````