马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下# -*- coding:utf-8 -*-
"""
@Author: 歌者文明清理员1410382
@Datetime: 2023-03-04 16:26:16
@Name: 双星系统.py
@OriginLink:
"""
from calc import *
a = obj(1, 0.5, vec(0.2, 0, 0), color.yellow, True, vec(0, 0, -10))
b = obj(1, 0.5, vec(-0.2, 0, 0), color.cyan, True, vec(0, 0, 10))
earth = obj(0.000000000000000000000000000000000001, 0.2, vec(0.2, 0.295, 0.01), color.blue, False, vec(0, 15, 0))
mainloop(1)
calc.py内容如下# -*- coding:utf-8 -*-
"""
@Author: 歌者文明清理员1410382
@Datetime: 2023-03-04 16:21:03
@Name: calc.py
@OriginLink:
"""
from vpython import *
def obj(mass, radius, momentum, color, emissive, pos, lock=False):
a = sphere(color=color, make_trail=True, retain=150, trail_width=radius / 10)
a.mass = mass
a.radius = radius
a.momentum = momentum
a.trail_color = color
a.emissive = emissive
a.pos = pos
a.locked = lock
if a.emissive:
attach_light(a)
stars.append(a)
return a
def move(g=1):
for sa in stars:
sa.pos += sa.momentum * (not sa.locked)
for sb in stars:
if sa == sb:
continue # samestar
distance = mag2(sa.pos-sb.pos)**1.5
if distance < limit:
distance = limit
force = g * sa.mass / \
distance * (sa.pos-sb.pos)
sb.momentum += force
def mainloop(dt=1, g=1):
scene.width, scene.height = 1900, 1050
scene.range = 100
while True:
rate(dt * 100)
move(g)
stars = []
limit = 0.001
每次都是甩出去,而且两个恒星慢慢的总是会相撞弹开
我知道弹开是因为,它们撞在一起时,距离的平方突然上升导致速度上升
准备工作pip install vpython -i https://mirrors.aliyun.com/pypi/simple
|