用户:Ugatrisy查看:0 回复:1 评论:0 创建时间:2021-05-08T00:10:42
【作品展示】

【作品介绍】
输入恒星质量,随机生成行星,显示参数
【作品源代码】
from arcade import *
import math
SW=800
SH=800
ST="Extraction Simulation"
GC=2.67*10**(-11)
class Star():
def __init__(self):
self.x=400
self.y=400
self.mass=mass
self.size=self.mass*10
def drawstar(self):
draw_circle_filled(self.x,self.y,self.size,color.TANGERINE)
class Planet(Star):
def __init__(self):
super().__init__()
self.px=400
self.py=400
self.angle=0
self.l=random.randint(200,300)
self.omega=math.sqrt(GC*self.mass*10**30/(self.l*10**9)**3)*57.29/self.l*(10**8)
def drawplanet(self):
draw_circle_filled(self.x+self.l*math.cos(math.radians(self.angle)),self.y+self.l*math.sin(math.radians(self.angle)),self.size/2,color.BLUE)
draw_text("恒星质量:"+str(self.mass)+"*10^30kg",30,100,font_size=15,font_name="fangzheng",color=color.WHITE)
draw_text("行星周期:"+str(round(2*math.pi/self.omega*3600*24,2))+"天",30,130,font_size=15,font_name="fangzheng",color=color.WHITE)
class gravity(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.setup()
def setup(self):
set_background_color(color.BLACK)
self.planet=Planet()
def on_draw(self):
start_render()
self.planet.drawstar()
self.planet.drawplanet()
def on_update(self,delta_time):
self.planet.angle-=self.planet.omega
# print(self.planet.angle)
print(self.planet.omega)
if __name__=="__main__":
mass = int(input("请输入恒星质量:(*10^30kg)"))
game = gravity(SW, SH, ST)
run()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn