# 地球绕着太阳转月亮绕着地球转.py

### 你好，请进入Q群:225792826，免费下载本站最新提供的视频教程原创源码资料,从2020年2月20号到3月底,成为本站会员只要原价的3折,即2980元*0.3 = 894元 ，向微信scratch8付款即可成为本站会员。即可拥有本站所有原创资源,并提供技术支持。如本消息修改,以最后时间的为准。

```"""地球绕着太阳转月亮绕着地球转.py"""
__author__ = "李兴球"
__date__ = "2018年5月"

import pygame
from pygame.locals import *
import math

pygame.init()
screenWidth,screenHeight=480,360
screenCenterx = screenWidth//2 -1
screenCentery = screenHeight//2 -1
screen = pygame.display.set_mode((screenWidth,screenHeight))
pygame.display.set_caption("太阳系公转,地月系_地球绕着太阳转月亮绕着地球转_作者:李兴球")

class Ball():
def __init__(self,r,color,speed):
"""球的半径,颜色和每次转的角速度"""
self.image = pygame.Surface((2*r,2*r))
pygame.draw.circle(self.image,color,(r,r),r)
self.image.set_colorkey((0,0,0))
self.rect = self.image.get_rect()
self.speed= speed
self.angle = 0
pass

def main():
earth = Ball(20,(0,0,255),1)
moon = Ball(10,(255,255,200),5)
clock = pygame.time.Clock()
运行中 = True
while 运行中:
for event in pygame.event.get():
if event.type==QUIT:运行中 =False
screen.fill((0,0,0))
pass
moon.move(earth.rect.centerx,earth.rect.centery,50)
moon.draw()
pygame.display.flip()
clock.tick(60)

pygame.quit()

if __name__ == "__main__":
main()
```

VIP免费查看