提交 c7aa8388 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 2a54d430
......@@ -226,7 +226,7 @@ class System(object):
if body1.mass / body2.mass < 1e10: # 10亿倍的差距
self.fast_calc_list[body1].append(body2)
else:
# print(f"{body2.name}相对{body1.name}质量太小,加速度可以忽略不计!")
print(f"{body2.name}相对{body1.name}质量太小,加速度可以忽略不计!")
continue
r = body2.position - body1.position
......
CC0 1.0 Universal (CC0 1.0)
Public Domain Dedication
http://creativecommons.org/publicdomain/zero/1.0/
--------------------------------------------------------------
Moreau Guillaume
\ No newline at end of file
### 数字 0-9 上标小数字特殊符号
```python
# ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹
```
# 模型下载
https://opengameart.org
此差异已折叠。
......@@ -316,9 +316,9 @@ class Obj(metaclass=ABCMeta):
return self.__density
def __repr__(self):
return '<%s(%s):%s(%s)> m=%.3e(kg), d=%.3e(kg/m³), p=[%.3e,%.3e,%.3e](km), v=%s(km/s)' % \
return '<%s(%s):%s(%s)> m=%.3e(kg), d=%.3e(kg/m³), p=[%.3e,%.3e,%.3e](km), v=%s(km/s), s=%.3e' % \
(self.name, self.__class__.__name__, os.path.basename(self.model), os.path.basename(self.texture), self.mass, self.density,
self.position[0], self.position[1], self.position[2], self.velocity)
self.position[0], self.position[1], self.position[2], self.velocity, self.size_scale)
def ignore_gravity_with(self, body):
"""
......
......@@ -43,15 +43,28 @@ class Rock(Obj):
super().__init__(**params)
def create_rock(no: str = None, **kwargs):
# 对岩石进行缩放,保证 create_rock 保证创建的岩石大小差异不会过大
ROCK_SIZE_SCALE_FACTOR = {
6: 1e-2,
7: 1e-2
}
def create_rock(no: int = None, **kwargs):
if no is not None:
kwargs["model"] = f"rock{no}.obj"
kwargs["texture"] = f"rock{no}.png"
if "size_scale" in kwargs:
kwargs["size_scale"] = kwargs["size_scale"] * ROCK_SIZE_SCALE_FACTOR.get(no, 1.0)
else:
kwargs["size_scale"] = ROCK_SIZE_SCALE_FACTOR.get(no, 1.0)
rock = Rock(**kwargs)
# print(rock)
return rock
if __name__ == '__main__':
for i in range(10):
rock = create_rock(no=i % 7 + 1, name=f'岩石{i + 1}')
rock = create_rock(no=i % 8 + 1, name=f'岩石{i + 1}')
print(rock)
# -*- coding:utf-8 -*-
# title :岩石坠落木星
# description :岩石坠落木星
# title :彗木相撞模拟
# description :天象奇观:彗木相撞模拟
# author :Python超人
# date :2023-04-09
# link :https://gitcode.net/pythoncr/
......@@ -11,18 +11,16 @@ from objs import RockSnow, Rock, create_rock
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY
from sim_scenes.func import ursina_run, camera_look_at, two_bodies_colliding
from simulators.ursina.entities.body_timer import TimeData
from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent
if __name__ == '__main__':
"""
岩石坠落木星
彗木相撞模拟
"""
import random
# 木星在中心位置
jupiter = Jupiter(init_position=[0, 0, 0], init_velocity=[0, 0, 0],
# rotation_speed=0,
size_scale=1, texture="jupiter_hd.jpg")
bodies = [jupiter]
......@@ -33,14 +31,15 @@ if __name__ == '__main__':
# 随机生成岩石位置和初始速度信息
pos = [-r * random.randint(120, 200) / 100,
-r * random.randint(120, 200) / 1000,
-r * random.randint(150, 350) / 100]
-r * random.randint(100, 300) / 100]
# 随机速度
vel = [0, -random.randint(90, 200) / 30, 0]
size_scale = random.randint(400, 600)
rock = create_rock(no=i % 7 + 1, name=f'岩石{i + 1}', mass=4.4e10, size_scale=size_scale, color=(255, 200, 0),
init_position=pos,
size_scale = random.randint(600, 1200)
rock = create_rock(no=i % 8 + 1, name=f'岩石{i + 1}', mass=4.4e10,
size_scale=size_scale, color=(255, 200, 0),
init_position=pos, init_velocity=vel,
gravity_only_for=[jupiter],
init_velocity=vel)
)
# 岩石随机旋转量
rock.rotation = [0, 0, 0]
rock.rotation[random.randint(0, 2)] = random.randint(90, 200) / 100
......
......@@ -97,12 +97,14 @@ class UrsinaSimulator(Simulator):
body.planet.enabled = False
explosion_file = find_file("images/explosion")
explosion_file = os.path.join(explosion_file, "explosion")
# volume = body.planet.model.volume
volume = pow(body.planet.model.get_bounds().volume, 1 / 3) / 2000
# 获取体积数据(开三次方)
volume_scale = pow(body.planet.model.get_bounds().volume, 1 / 3)
# 根据体积、大小缩放判断爆炸的量
scale = 3 * volume_scale * body.size_scale * UrsinaConfig.SCALE_FACTOR
explode_ani = Animation(explosion_file,
position=body.planet.position,
scale=volume * 2, fps=6,
loop=False, autoplay=True)
position=body.planet.position,
scale=scale, fps=6,
loop=False, autoplay=True)
if target is not None:
if hasattr(target, "planet"):
......
textures/jupiter_hd.jpg

320.9 KB | W: | H:

textures/jupiter_hd.jpg

1.8 MB | W: | H:

textures/jupiter_hd.jpg
textures/jupiter_hd.jpg
textures/jupiter_hd.jpg
textures/jupiter_hd.jpg
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册