zhong (钟鹏群) hace 1 mes
padre
commit
d803edef70
Se han modificado 1 ficheros con 11 adiciones y 5 borrados
  1. 11 5
      ball-demo.py

+ 11 - 5
ball-demo.py

@@ -16,8 +16,14 @@ from OpenGL.GLU import *
 # 初始化 Pygame
 pygame.init()
 
-# 设置窗口大小
-width, height = 800, 600
+# 获取屏幕尺寸
+info = pygame.display.Info()
+screen_width = info.current_w
+screen_height = info.current_h
+
+# 设置窗口大小(高度为屏幕高度的80%,保持原始宽高比)
+height = int(screen_height * 0.8)
+width = int(height * (800 / 600))  # 保持原始宽高比 800:600
 display = pygame.display.set_mode((width, height), DOUBLEBUF | OPENGL)
 pygame.display.set_caption('3D Yellow Ball')
 
@@ -122,7 +128,7 @@ def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
         
         # 计算当前节点位置
         if node_id == 0:  # 根节点
-            positions[node_id] = [0.0, max_depth_found * 0.8, 0.0]  # 顶部
+            positions[node_id] = [0.0, max_depth_found * 0.4, 0.0]  # 顶部,高度减半
         else:
             parent_id = nodes[node_id][2]
             if parent_id >= 0:
@@ -134,12 +140,12 @@ def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
                 angle = start_angle + (end_angle - start_angle) * (child_index / max(num_siblings, 1))
                 
                 # 半径随深度减小
-                radius = 1.5 * (0.75 ** depth)  # 深度越大,半径越小
+                radius = 0.75 * (0.75 ** depth)  # 深度越大,半径越小,基础半径减半
                 
                 # 计算位置
                 px, py, pz = positions[parent_id]
                 x = px + radius * math.cos(angle)
-                y = py - 1.3  # 每层向下移动
+                y = py - 0.65  # 每层向下移动,垂直距离减半
                 z = pz + radius * math.sin(angle)
                 
                 positions[node_id] = [x, y, z]