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

Python超人-宇宙模拟器

上级 02fa3606
......@@ -34,6 +34,54 @@ def conv_to_vec4_color(colour: tuple, alpha=1):
# color = ursina_color.rgba(r, g, b, a)
# def brightest(color):
# if isinstance(color, tuple):
# r, g, b = color
# elif isinstance(color, list):
# r, g, b = color
#
# brightest_color 等于的值就是 r g b 同时按照比例增加,直到 r g b 其中一个值达到 255 为止,
# 比如: r=127 g=20 b=40,则 brightest_color=127*2 约等于 255, g=20*2=40 b=40*2=80
# brightest_color的 r g b 就等于 255 40 80
# 请实现以下代码:
# TODO:
#
#
# return brightest_color
def brightest(color):
if isinstance(color, tuple):
r, g, b = color
elif isinstance(color, list):
r, g, b = color
b_color = [r, g, b]
max_value = max(r, g, b)
if max_value < 255:
multiplier = 255 / max_value
b_color = [value * multiplier if value * multiplier <= 255 else 255 for value in b_color]
r, g, b = int(b_color[0]), int(b_color[1]), int(b_color[2])
if isinstance(color, tuple):
return r, g, b
elif isinstance(color, list):
return [r, g, b]
def trail_color_brightest(bodies):
"""
天体尾巴最亮
@param bodies:
@return:
"""
for body in bodies:
c = body.trail_color
if c is None:
c = body.color
if c is None:
c = (255, 255, 255)
bc = brightest(c)
body.trail_color = bc
def adjust_brightness(color, target_brightness: float = 0.6):
"""
调整颜色的亮度到目标 target_brightness(确保亮度不超过 1.0)
......@@ -68,3 +116,7 @@ def get_inverse_color(color):
inverse_g = 255 - g
inverse_b = 255 - b
return inverse_r, inverse_g, inverse_b
if __name__ == '__main__':
print(brightest((100, 20, 50)))
......@@ -12,6 +12,7 @@ from ursina import camera, application
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto
from common.celestial_data_service import get_init_pos_vels, init_bodies_pos_vels
from common.color_utils import brightest, trail_color_brightest
from common.consts import SECONDS_PER_YEAR, AU
from common.func import calculate_distance
from objs import HalleComet, Obj
......@@ -55,7 +56,7 @@ class HalleyCometSim:
self.pluto, # 冥王星
]
# endregion
trail_color_brightest(self.bodies)
init_bodies_pos_vels(self.bodies)
def build_halley_comet(self):
......
......@@ -12,6 +12,7 @@ from ursina import camera, application
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto
from common.celestial_data_service import get_init_pos_vels, init_bodies_reality_pos_vels
from common.color_utils import trail_color_brightest
from common.consts import SECONDS_PER_YEAR, AU
from common.func import calculate_distance
from objs import HalleComet, Obj
......@@ -62,7 +63,7 @@ class HalleyCometSim:
self.neptune, # 海王星
]
# endregion
trail_color_brightest(self.bodies)
init_bodies_reality_pos_vels(self.bodies)
def build_halley_comet(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册