# -*- coding:utf-8 -*- # title :地球季节(四季和24节气)函数功能 # description : # author :Python超人 # date :2023-02-11 # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from ursina import camera from bodies import Sun, Earth from common.consts import SECONDS_PER_DAY, AU def create_trans_earth(name, text_color, position, texture="earth_transparent.png", size_scale=5e3): """ 创建透明的地球 @param name: 名称 @param text_color: 文字颜色 @param position: 地球的位置 @param texture: 透明地球的纹理图片 @return: """ return Earth(name=name, size_scale=size_scale, texture=texture, # 明的地球纹理 text_color=text_color, rotation_speed=0, init_position=position, init_velocity=[0, 0, 0]).set_ignore_gravity(True) # 忽略重力 def create_important_pos_earths(texture="earth_transparent.png", size_scale=5e3, position_offset=1.05): """ 创建24节气中4个重要位置的透明地球 @param texture: 透明地球的纹理图片 @param size_scale: @param position_offset: @return: """ earth_1 = create_trans_earth(name="春分", text_color=(0, 255, 0), position=[-position_offset * AU, 0, 0], texture=texture, size_scale=size_scale) earth_2 = create_trans_earth(name="夏至", text_color=(255, 0, 0), position=[0, 0, -position_offset * AU], texture=texture, size_scale=size_scale) earth_3 = create_trans_earth(name="秋分", text_color=(255, 255, 0), position=[position_offset * AU, 0, 0], texture=texture, size_scale=size_scale) earth_4 = create_trans_earth(name="冬至", text_color=(0, 255, 255), position=[0, 0, position_offset * AU], texture=texture, size_scale=size_scale) earth_1.set_light_disable(True) earth_2.set_light_disable(True) earth_3.set_light_disable(True) earth_4.set_light_disable(True) return earth_1, earth_2, earth_3, earth_4 def create_earth(earth_texture="earth_hd.jpg", with_clouds=False, clouds_texture="transparent_clouds.png", earth_rotation_speed=0.5, clouds_rotation_speed=0.5): """ 创建运动的地球(和云层) @param earth_texture: 地球的纹理图片 @param with_clouds: 是否创建云层 @param clouds_texture: 地球云层的纹理图片 @param earth_rotation_speed: 地球自转速度(为演示效果,自转角速度取0.5度/小时,实际为15度/小时) @param clouds_rotation_speed: 地球云层的自转速度 @return: """ # 运动的地球 earth = Earth(size_scale=5e3, texture=earth_texture, text_color=[255, 255, 255], rotation_speed=earth_rotation_speed, init_position=[-1 * AU, 0, 0], init_velocity=[0, 0, -29.79]) if not with_clouds: return earth # 创建云层(texture纹理图使用了透明云层的图片,云层的 size_scale 要稍微比地球大一点) earth_clouds = Earth(name="", texture=clouds_texture, rotation_speed=clouds_rotation_speed, show_name=False, size_scale=1.01 * 5e3, parent=earth) return earth, earth_clouds def get_solar_terms_angles(): """ 中国农历24节气表,数据为 节气名称 和 camera.rotation_y 的角度范围值 @return: """ solar_terms_angles = [ ("小寒", -22.5, -7.5), ("大寒", -37.5, -22.5), ("立春", -52.5, -37.5), ("雨水", -67.5, -52.5), ("惊蛰", -82.5, -67.5), ("春分", -97.5, -82.5), ("清明", -112.5, -97.5), ("谷雨", -127.5, -112.5), ("立夏", -142.5, -127.5), ("小满", -157.5, -142.5), ("芒种", -172.5, -157.5), ("夏至", -180, -172.5), ("夏至", 172.5, 180), ("小暑", 157.5, 172.5), ("大暑", 142.5, 157.5), ("立秋", 127.5, 142.5), ("处暑", 112.5, 127.5), ("白露", 97.5, 112.5), ("秋分", 82.5, 97.5), ("寒露", 67.5, 82.5), ("霜降", 52.5, 67.5), ("立冬", 37.5, 52.5), ("小雪", 22.5, 37.5), ("大雪", 7.5, 22.5), ("冬至", -7.5, 7.5)] return solar_terms_angles def get_earth_pos_vel_by_term_name(term_name): """ 根据节气获取地球的初始速度和未知 @param term_name: @return: """ pos_vels = {"立春": {"pos": [-91429152.0, 0.0, 119128416.0], "vel": [-23.56348419189453, 0.0, -18.03900146484375]} , "雨水": {"pos": [-119206008.0, 0.0, 91364824.0], "vel": [-18.053457260131836, 0.0, -23.547433853149414]} , "惊蛰": {"pos": [-138759232.0, 0.0, 57409412.0], "vel": [-11.321699142456055, 0.0, -27.432178497314453]} , "春分": {"pos": [-148826464.0, 0.0, 19529740.0], "vel": [-3.809511184692383, 0.0, -29.443904876708984]} , "清明": {"pos": [-148717568.0, 0.0, -19601100.0], "vel": [3.959000825881958, 0.0, -29.443849563598633]} , "谷雨": {"pos": [-138453296.0, 0.0, -57392344.0], "vel": [11.474220275878906, 0.0, -27.430706024169922]} , "立夏": {"pos": [-118763752.0, 0.0, -91185672.0], "vel": [18.209632873535156, 0.0, -23.541967391967773]} , "小满": {"pos": [-91024856.0, 0.0, -118692480.0], "vel": [23.708106994628906, 0.0, -18.04340171813965]} , "芒种": {"pos": [-57152380.0, 0.0, -138062688.0], "vel": [27.595821380615234, 0.0, -11.310075759887695]} , "夏至": {"pos": [-19469878.0, 0.0, -148008528.0], "vel": [29.608537673950195, 0.0, -3.801793098449707]} , "小暑": {"pos": [19536654.0, 0.0, -147878576.0], "vel": [29.60844612121582, 0.0, 3.9851362705230713]} , "大暑": {"pos": [57050156.0, 0.0, -137724432.0], "vel": [27.59927749633789, 0.0, 11.484448432922363]} , "立秋": {"pos": [90765216.0, 0.0, -118185768.0], "vel": [23.70542335510254, 0.0, 18.229616165161133]} , "处暑": {"pos": [118243424.0, 0.0, -90663376.0], "vel": [18.207006454467773, 0.0, 23.726715087890625]} , "白露": {"pos": [137697808.0, 0.0, -56988980.0], "vel": [11.4738187789917, 0.0, 27.613632202148438]} , "秋分": {"pos": [147813104.0, 0.0, -19449096.0], "vel": [3.9687302112579346, 0.0, 29.625364303588867]} , "寒露": {"pos": [147904608.0, 0.0, 19494148.0], "vel": [-3.810037851333618, 0.0, 29.62670135498047]} , "霜降": {"pos": [137919376.0, 0.0, 57194016.0], "vel": [-11.329061508178711, 0.0, 27.612049102783203]} , "立冬": {"pos": [118550400.0, 0.0, 91003808.0], "vel": [-18.058313369750977, 0.0, 23.726837158203125]} , "小雪": {"pos": [91069912.0, 0.0, 118693304.0], "vel": [-23.554834365844727, 0.0, 18.23233985900879]} , "大雪": {"pos": [57243580.0, 0.0, 138386736.0], "vel": [-27.450029373168945, 0.0, 11.48636245727539]} , "冬至": {"pos": [19504978.0, 0.0, 148626512.0], "vel": [-29.46121597290039, 0.0, 3.9764606952667236]} , "小寒": {"pos": [-19648712.0, 0.0, 148729504.0], "vel": [-29.460290908813477, 0.0, -3.801400661468506]} , "大寒": {"pos": [-57462344.0, 0.0, 138679984.0], "vel": [-27.450258255004883, 0.0, -11.3037691116333]} } return pos_vels.get(term_name, None)