3 Commits 2843ff308f ... 884c1d07ee

Autore SHA1 Messaggio Data
  zhong (钟鹏群) 884c1d07ee ok3 3 settimane fa
  zhong (钟鹏群) c7049fdec0 ok2 3 settimane fa
  zhong (钟鹏群) d012ecc88f cube 3 settimane fa
8 ha cambiato i file con 1289 aggiunte e 13 eliminazioni
  1. BIN
      src/__pycache__/ball-demo.cpython-310.pyc
  2. 34 2
      src/ball-demo.py
  3. 134 0
      src/new.py
  4. 299 0
      src/square.py
  5. 322 0
      src/xxx.py
  6. 190 11
      src/yuan.py
  7. 180 0
      src/yuan2.py
  8. 130 0
      src/yyy.py

BIN
src/__pycache__/ball-demo.cpython-310.pyc


+ 34 - 2
src/ball-demo.py

@@ -40,6 +40,19 @@ RABBITMQ_USERNAME = 'admin'  # 默认用户名
 RABBITMQ_PASSWORD = 'zpq123456'  # 默认密码
 
 # 发送消息到 RabbitMQ
+def count_files_recursive(directory_path):
+    """递归计算目录中的文件总数"""
+    count = 0
+    try:
+        for root, dirs, files in os.walk(directory_path):
+            # 排除不需要的目录
+            dirs[:] = [d for d in dirs if d not in EXCLUDED_DIR]
+            count += len(files)
+    except Exception:
+        pass  # 忽略访问错误
+    return count
+
+
 def send_to_rabbitmq(message):
     """发送消息到 RabbitMQ"""
     if not rabbitmq_available:
@@ -281,12 +294,31 @@ def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
                 # 这行代码确保多个子节点在指定的角度范围内均匀分布,避免它们在3D空间中重叠或拥挤。例如,如果起始角度是0度,结束角度是360度,有4个子节点,那么它们的角度会分别是0度、90度、180度和270度,均匀分布在圆周上
                 angle = start_angle + (end_angle - start_angle) * (child_index / max(num_siblings, 1))
                 
-                # 半径随深度减小
+                # 半径随深度减小,并考虑文件数量
                 # radius = 0.75 * (0.75 ** depth)  # 深度越大,半径越小,基础半径减半
                 if depth == 1:
                     radius = 1.5
                 else:
-                    radius = 0.75 * (0.75 ** depth)  # 深度越大,半径越小,基础半径减半
+                    # 计算当前节点所在目录的文件数量
+                    current_node_path = nodes[node_id][4]  # 获取节点的完整路径
+                    # if nodes[node_id][1]:  # 如果是目录节点
+                    #     file_count = count_files_recursive(current_node_path)
+                    # else:  # 如果是文件节点,获取其父目录的文件数
+                    #     parent_path = os.path.dirname(current_node_path)
+                    #     file_count = count_files_recursive(parent_path)
+
+                    if nodes[node_id][1]:  # 如果是目录节点
+                        file_count = count_files_recursive(current_node_path)
+                    else:  # 如果是文件节点,获取其父目录的文件数
+                        file_count = 1
+
+                    # 基础半径随深度减小,但根据文件数量进行调整
+                    # base_radius = 0.75 * (0.75 ** depth)
+                    base_radius = 0.75 * (0.85 ** depth)
+
+                    # 文件数量越多,半径越大,但需要控制增长幅度
+                    file_count_factor = 0.4 + (math.log(file_count + 1) * 0.1) if file_count > 0 else 1
+                    radius = base_radius * file_count_factor  # 深度越大,半径越小,基础半径减半
                 
                 # 计算位置
                 px, py, pz = positions[parent_id]

+ 134 - 0
src/new.py

@@ -0,0 +1,134 @@
+"""
+This is a new Python file created to display a directory tree as a table 
+with width set to 90% of the window using tkinter GUI.
+"""
+
+import os
+import tkinter as tk
+
+class DirectoryTableGUI:
+    def __init__(self, root):
+        self.root = root
+        self.root.title("Directory Tree Table")
+        # Set window size to 1200x1000 pixels
+        self.root.geometry("1200x1000")
+        
+        # Calculate 90% of window width
+        table_width = int(1200 * 0.9)  # 90% of 1200 = 1080
+        
+        # Configure the main frame
+        main_frame = tk.Frame(root)
+        main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
+        
+        # Create a label to indicate the table
+        table_label = tk.Label(main_frame, text="Directory Tree Table (Width: 90% of window)", 
+                              font=("Arial", 14, "bold"))
+        table_label.pack(pady=(0, 10))
+        
+        # Create a frame for the table with specified width
+        table_frame = tk.Frame(main_frame, width=table_width, bg="black", 
+                              relief=tk.RAISED, bd=2)
+        table_frame.pack_propagate(False)  # Prevent frame from shrinking to fit contents
+        table_frame.pack(padx=10)
+        
+        # Define the root directory path
+        root_dir = r"E:\agricultural_research_platform"
+        root_name = os.path.basename(root_dir)
+        
+        # Count the number of directories in the root directory
+        try:
+            items = os.listdir(root_dir)
+            directories = [item for item in items if os.path.isdir(os.path.join(root_dir, item))]
+            original_n_dirs = len(directories)  # Keep track of original count
+            
+            # Limit to 20 directories + 1 for files, with an extra slot for ellipsis if needed
+            if original_n_dirs > 20:
+                directories = directories[:20]  # Take only first 20
+                n_dirs = 20
+                has_more_dirs = True
+            else:
+                n_dirs = original_n_dirs
+                has_more_dirs = False
+            
+            # Calculate total columns: n_dirs + 1 for files + 1 for ellipsis (if needed)
+            n_cols_second_row = n_dirs + 1  # n directories + 1 for files
+            if has_more_dirs:
+                n_cols_second_row += 1  # Add one more for ellipsis
+        except FileNotFoundError:
+            n_dirs = 0
+            n_cols_second_row = 1  # Just one column for "no directories found"
+            directories = []
+            has_more_dirs = False
+        
+        print(f"DEBUG: Found {original_n_dirs} directories, showing {n_dirs}, has_more_dirs={has_more_dirs}, n_cols_second_row={n_cols_second_row}")
+        
+        # Create merged cell for the first row spanning all columns of the second row
+        cell_width = table_width  # Full width for the merged cell
+        
+        # First row: merged cell containing root directory name
+        root_cell = tk.Label(table_frame, 
+                            text=f"Root: {root_name} ({original_n_dirs} folders)",
+                            bg="lightyellow",
+                            relief=tk.RAISED,
+                            bd=1,
+                            font=("Arial", 14, "bold"),
+                            width=cell_width//8,  # Approximate character width
+                            height=3,
+                            wraplength=cell_width-20)  # Wrap text if needed
+        root_cell.grid(row=0, column=0, columnspan=n_cols_second_row, sticky="nsew", padx=1, pady=1)  # columnspan merges all columns of second row
+        
+        # Second row: create cells (up to 20 directories + 1 for files + 1 for ellipsis if needed)
+        for col in range(n_cols_second_row):
+            # Calculate width for each cell (table_width divided by n_cols_second_row columns)
+            cell_width = table_width // n_cols_second_row
+            
+            if col < n_dirs:
+                # Directory cell
+                cell_text = f"[{directories[col]}]"
+                cell_bg = "lightgreen"
+            elif col == n_dirs and has_more_dirs:
+                # Ellipsis cell to indicate more directories
+                cell_text = f"... (+{original_n_dirs - 20})"
+                cell_bg = "lightgray"
+            elif col == n_cols_second_row - 1:  # Last column is always files
+                # Files cell (always in the last position)
+                files_list = [item for item in items if os.path.isfile(os.path.join(root_dir, item))]
+                cell_text = f"All Files ({len(files_list)})"
+                cell_bg = "lightcoral"
+            else:
+                # Fallback for any remaining indices
+                cell_text = f"Col {col+1}"
+                cell_bg = "lightblue"
+            
+            print(f"DEBUG: Creating cell at col {col}, text: {cell_text}")
+            
+            cell = tk.Label(table_frame, 
+                           text=cell_text,
+                           bg=cell_bg,
+                           relief=tk.RAISED,
+                           bd=1,
+                           font=("Arial", 10),
+                           width=cell_width//8,  # Approximate character width
+                           height=5,
+                           wraplength=cell_width//2)  # Wrap text if needed
+            cell.grid(row=1, column=col, sticky="nsew", padx=1, pady=1)
+        
+        # Configure grid weights so cells expand proportionally
+        for i in range(n_cols_second_row):
+            table_frame.grid_columnconfigure(i, weight=1)
+        for i in range(2):  # Two rows for now
+            table_frame.grid_rowconfigure(i, weight=1)
+
+
+def main():
+    # Create the main window
+    root = tk.Tk()
+    
+    # Initialize the directory table GUI
+    app = DirectoryTableGUI(root)
+    
+    # Start the GUI event loop
+    root.mainloop()
+
+if __name__ == "__main__":
+    main()

+ 299 - 0
src/square.py

@@ -0,0 +1,299 @@
+import pygame
+import math
+import random
+from pygame.locals import *
+from OpenGL.GL import *
+from OpenGL.GLU import *
+
+# 初始化Pygame和OpenGL
+pygame.init()
+
+# 设置窗口大小
+WIDTH, HEIGHT = 800, 800
+screen = pygame.display.set_mode((WIDTH, HEIGHT), DOUBLEBUF | OPENGL)
+pygame.display.set_caption("3D立方体容器 - 透明立方体")
+
+# 设置OpenGL视角
+gluPerspective(45, (WIDTH / HEIGHT), 0.1, 50.0)
+glTranslatef(0.0, 0.0, -5)
+
+# 启用深度测试和混合
+glEnable(GL_DEPTH_TEST)
+glEnable(GL_BLEND)
+glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+class Cube:
+    def __init__(self, x, y, z, size, color):
+        self.x = x
+        self.y = y
+        self.z = z
+        self.size = size
+        self.color = color
+        self.rotation_x = 0
+        self.rotation_y = 0
+        self.rotation_z = 0
+        self.vx = random.uniform(-0.01, 0.01)
+        self.vy = random.uniform(-0.01, 0.01)
+        self.vz = random.uniform(-0.01, 0.01)
+        
+    def move(self, container_size):
+        # 更新位置
+        self.x += self.vx
+        self.y += self.vy
+        self.z += self.vz
+        
+        # 检查与大立方体边界的碰撞
+        half_size = container_size / 2
+        cube_half = self.size / 2
+        
+        if abs(self.x) + cube_half > half_size:
+            self.x = (half_size - cube_half) * (1 if self.x >= 0 else -1)
+            self.vx *= -1
+        if abs(self.y) + cube_half > half_size:
+            self.y = (half_size - cube_half) * (1 if self.y >= 0 else -1)
+            self.vy *= -1
+        if abs(self.z) + cube_half > half_size:
+            self.z = (half_size - cube_half) * (1 if self.z >= 0 else -1)
+            self.vz *= -1
+    
+    def draw(self):
+        glPushMatrix()
+        glColor4f(self.color[0], self.color[1], self.color[2], self.color[3])  # 包含透明度
+        glTranslatef(self.x, self.y, self.z)
+        glRotatef(self.rotation_x, 1, 0, 0)
+        glRotatef(self.rotation_y, 0, 1, 0)
+        glRotatef(self.rotation_z, 0, 0, 1)
+        
+        # 绘制立方体
+        half_size = self.size / 2
+        vertices = (
+            (half_size, -half_size, -half_size),
+            (half_size, half_size, -half_size),
+            (-half_size, half_size, -half_size),
+            (-half_size, -half_size, -half_size),
+            (half_size, -half_size, half_size),
+            (half_size, half_size, half_size),
+            (-half_size, -half_size, half_size),
+            (-half_size, half_size, half_size)
+        )
+        
+        edges = (
+            (0,1), (1,2), (2,3), (3,0),  # 底面
+            (4,5), (5,7), (7,6), (6,4),  # 顶面
+            (0,4), (1,5), (2,7), (3,6)   # 连接边
+        )
+        
+        glBegin(GL_LINES)
+        for edge in edges:
+            for vertex in edge:
+                glVertex3fv(vertices[vertex])
+        glEnd()
+        
+        # 绘制面以增加立体感
+        faces = (
+            (0,1,2,3),  # 底面
+            (4,5,7,6),  # 顶面
+            (0,1,5,4),  # 前面
+            (2,3,6,7),  # 后面
+            (0,3,6,4),  # 左面
+            (1,2,7,5)   # 右面
+        )
+        
+        glBegin(GL_QUADS)
+        for face in faces:
+            for vertex in face:
+                glVertex3fv(vertices[vertex])
+        glEnd()
+        
+        glPopMatrix()
+
+def draw_container_cube(size):
+    glColor4f(1.0, 1.0, 1.0, 0.1)  # 白色,10% alpha (90% 透明度)
+    
+    half_size = size / 2
+    vertices = (
+        (half_size, -half_size, -half_size),
+        (half_size, half_size, -half_size),
+        (-half_size, half_size, -half_size),
+        (-half_size, -half_size, -half_size),
+        (half_size, -half_size, half_size),
+        (half_size, half_size, half_size),
+        (-half_size, -half_size, half_size),
+        (-half_size, half_size, half_size)
+    )
+    
+    edges = (
+        (0,1), (1,2), (2,3), (3,0),  # 底面
+        (4,5), (5,7), (7,6), (6,4),  # 顶面
+        (0,4), (1,5), (2,7), (3,6)   # 连接边
+    )
+    
+    glBegin(GL_LINES)
+    for edge in edges:
+        for vertex in edge:
+            glVertex3fv(vertices[vertex])
+    glEnd()
+    
+    # 绘制面以增加立体感
+    faces = (
+        (0,1,2,3),  # 底面
+        (4,5,7,6),  # 顶面
+        (0,1,5,4),  # 前面
+        (2,3,6,7),  # 后面
+        (0,3,6,4),  # 左面
+        (1,2,7,5)   # 右面
+    )
+    
+    glBegin(GL_QUADS)
+    for face in faces:
+        for vertex in face:
+            glVertex3fv(vertices[vertex])
+    glEnd()
+
+def check_collision(cube1, cube2):
+    # 简单的边界框碰撞检测
+    half_size1 = cube1.size / 2
+    half_size2 = cube2.size / 2
+    
+    # 检查各轴是否有重叠
+    x_overlap = abs(cube1.x - cube2.x) < (half_size1 + half_size2)
+    y_overlap = abs(cube1.y - cube2.y) < (half_size1 + half_size2)
+    z_overlap = abs(cube1.z - cube2.z) < (half_size1 + half_size2)
+    
+    if x_overlap and y_overlap and z_overlap:
+        # 发生碰撞,交换速度分量
+        cube1.vx, cube2.vx = cube2.vx, cube1.vx
+        cube1.vy, cube2.vy = cube2.vy, cube1.vy
+        cube1.vz, cube2.vz = cube2.vz, cube1.vz
+        
+        # 分离立方体以避免重叠
+        min_dist = half_size1 + half_size2
+        dist_x = abs(cube1.x - cube2.x)
+        dist_y = abs(cube1.y - cube2.y)
+        dist_z = abs(cube1.z - cube2.z)
+        
+        if dist_x < dist_y and dist_x < dist_z:
+            # X轴方向分离
+            sign = 1 if cube1.x < cube2.x else -1
+            cube1.x -= sign * (min_dist - dist_x) / 2
+            cube2.x += sign * (min_dist - dist_x) / 2
+        elif dist_y < dist_z:
+            # Y轴方向分离
+            sign = 1 if cube1.y < cube2.y else -1
+            cube1.y -= sign * (min_dist - dist_y) / 2
+            cube2.y += sign * (min_dist - dist_y) / 2
+        else:
+            # Z轴方向分离
+            sign = 1 if cube1.z < cube2.z else -1
+            cube1.z -= sign * (min_dist - dist_z) / 2
+            cube2.z += sign * (min_dist - dist_z) / 2
+
+def main():
+    clock = pygame.time.Clock()
+    
+    # 大立方体参数
+    container_size = 3.0
+    
+    # 创建3个小立方体
+    cubes = []
+    cube_size = 0.4  # 小立方体尺寸
+    
+    # 随机生成小立方体的位置,确保它们不重叠
+    for i in range(3):
+        placed = False
+        attempts = 0
+        while not placed and attempts < 1000:
+            # 在大立方体内部随机选择一个位置
+            half_container = container_size / 2 - cube_size / 2
+            x = random.uniform(-half_container, half_container)
+            y = random.uniform(-half_container, half_container)
+            z = random.uniform(-half_container, half_container)
+            
+            # 检查是否与其他立方体重叠
+            valid_position = True
+            for other_cube in cubes:
+                dx = x - other_cube.x
+                dy = y - other_cube.y
+                dz = z - other_cube.z
+                distance = math.sqrt(dx**2 + dy**2 + dz**2)
+                min_distance = cube_size  # 最小安全距离
+                if distance < min_distance:
+                    valid_position = False
+                    break
+            
+            if valid_position:
+                # 白色,90% 透明度
+                cubes.append(Cube(x, y, z, cube_size, (1.0, 1.0, 1.0, 0.1)))
+                placed = True
+            
+            attempts += 1
+        
+        if not placed:
+            print(f"无法放置第 {i+1} 个小立方体,可能空间不足")
+            break
+    
+    rotation_x = 0
+    rotation_y = 0
+    drag = False
+    last_pos = (0, 0)
+    
+    running = True
+    while running:
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT:
+                running = False
+            elif event.type == pygame.KEYDOWN:
+                if event.key == pygame.K_ESCAPE:
+                    running = False
+            elif event.type == pygame.MOUSEBUTTONDOWN:
+                if event.button == 1:  # 左键按下
+                    drag = True
+                    last_pos = event.pos
+            elif event.type == pygame.MOUSEBUTTONUP:
+                if event.button == 1:  # 左键释放
+                    drag = False
+            elif event.type == pygame.MOUSEMOTION:
+                if drag:
+                    dx = event.pos[0] - last_pos[0]
+                    dy = event.pos[1] - last_pos[1]
+                    rotation_y += dx * 0.5
+                    rotation_x += dy * 0.5
+                    last_pos = event.pos
+        
+        # 清除屏幕和深度缓冲区
+        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+        
+        # 应用旋转
+        glPushMatrix()
+        glRotatef(rotation_x, 1, 0, 0)
+        glRotatef(rotation_y, 0, 1, 0)
+        
+        # 绘制大立方体容器
+        draw_container_cube(container_size)
+        
+        # 移动所有小立方体并检查边界碰撞
+        for cube in cubes:
+            cube.move(container_size)
+            # 更新旋转
+            cube.rotation_x += 0.5
+            cube.rotation_y += 0.3
+            cube.rotation_z += 0.2
+        
+        # 检查小立方体之间的碰撞
+        for i in range(len(cubes)):
+            for j in range(i + 1, len(cubes)):
+                check_collision(cubes[i], cubes[j])
+        
+        # 绘制所有小立方体
+        for cube in cubes:
+            cube.draw()
+        
+        glPopMatrix()
+        
+        pygame.display.flip()
+        clock.tick(60)
+    
+    pygame.quit()
+
+if __name__ == "__main__":
+    main()

+ 322 - 0
src/xxx.py

@@ -0,0 +1,322 @@
+import pygame
+from pygame.locals import *
+from OpenGL.GL import *
+from OpenGL.GLU import *
+import math
+
+def draw_wire_cube():
+    """绘制线框立方体"""
+    # 定义8个顶点
+    vertices = (
+        (1, -1, -1),
+        (1, 1, -1),
+        (-1, 1, -1),
+        (-1, -1, -1),
+        (1, -1, 1),
+        (1, 1, 1),
+        (-1, -1, 1),
+        (-1, 1, 1)
+    )
+
+    # 定义12条边
+    edges = (
+        (0,1),
+        (0,3),
+        (0,4),
+        (2,1),
+        (2,3),
+        (2,7),
+        (6,3),
+        (6,4),
+        (6,7),
+        (5,1),
+        (5,4),
+        (5,7)
+    )
+
+    glBegin(GL_LINES)
+    for edge in edges:
+        for vertex in edge:
+            glVertex3fv(vertices[vertex])
+    glEnd()
+
+def draw_solid_cube():
+    """绘制实心立方体(带透明度)"""
+    # 定义8个顶点
+    vertices = (
+        (1, -1, -1),
+        (1, 1, -1),
+        (-1, 1, -1),
+        (-1, -1, -1),
+        (1, -1, 1),
+        (1, 1, 1),
+        (-1, -1, 1),
+        (-1, 1, 1)
+    )
+
+    # 定义6个面
+    surfaces = (
+        (0, 1, 2, 3),  # 后面
+        (4, 5, 7, 6),  # 前面
+        (0, 4, 6, 3),  # 底面
+        (1, 5, 7, 2),  # 顶面
+        (0, 1, 5, 4),  # 右面
+        (2, 3, 6, 7)   # 左面
+    )
+
+    # 设置透明度
+    glEnable(GL_BLEND)
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+    # 绘制每个面
+    for surface in surfaces:
+        glBegin(GL_QUADS)
+        glColor4f(0.0, 0.5, 1.0, 0.1)  # 蓝色,70%透明度(更透明)
+        for vertex in surface:
+            glVertex3fv(vertices[vertex])
+        glEnd()
+
+# 字体初始化
+font = None
+
+def init_font():
+    global font
+    pygame.font.init()
+    font = pygame.font.SysFont('arial', 24)
+
+def draw_text_at_position(text, position):
+    """在3D空间中指定位置绘制文本"""
+    global font
+    if font is None:
+        init_font()
+    
+    # 创建文本表面
+    text_surface = font.render(text, True, (255, 255, 255))  # 白色文字
+    text_data = pygame.image.tostring(text_surface, "RGBA", True)
+    
+    # 保存当前矩阵状态
+    glPushMatrix()
+    
+    # 移动到目标位置
+    glTranslatef(position[0], position[1], position[2])
+    
+    # 获取模型视图矩阵,使文本面向摄像机
+    matrix = glGetFloatv(GL_MODELVIEW_MATRIX)
+    
+    # 使文本始终面向摄像机(billboard效果)
+    glLoadIdentity()
+    # 恢复摄像机视角,但保持位置
+    glTranslatef(position[0], position[1], position[2])
+    
+    # 创建纹理
+    texture_id = glGenTextures(1)
+    glBindTexture(GL_TEXTURE_2D, texture_id)
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, text_surface.get_width(), 
+                 text_surface.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, text_data)
+    
+    # 计算文本尺寸以适当缩放
+    width = text_surface.get_width()
+    height = text_surface.get_height()
+    scale_factor = 0.05  # 缩放因子
+    
+    # 绘制带纹理的四边形来显示文本
+    glEnable(GL_TEXTURE_2D)
+    glEnable(GL_BLEND)
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+    
+    glBegin(GL_QUADS)
+    glTexCoord2f(0, 0); glVertex3f(-width * scale_factor/2, -height * scale_factor/2, 0.01)  # 稍微高于小正方体表面
+    glTexCoord2f(1, 0); glVertex3f(width * scale_factor/2, -height * scale_factor/2, 0.01)
+    glTexCoord2f(1, 1); glVertex3f(width * scale_factor/2, height * scale_factor/2, 0.01)
+    glTexCoord2f(0, 1); glVertex3f(-width * scale_factor/2, height * scale_factor/2, 0.01)
+    glEnd()
+    
+    glDisable(GL_TEXTURE_2D)
+    
+    # 清理纹理
+    glDeleteTextures([texture_id])
+    
+    glPopMatrix()
+
+def draw_small_cube(position, cube_number, size=0.4):
+    """绘制一个小正方体
+    position: 小正方体的位置 (x, y, z)
+    cube_number: 小正方体的编号 (从1开始)
+    size: 小正方体的大小 (默认为0.4,即大正方体的一半减去0.1单位)
+    """
+    x, y, z = position
+    
+    # 定义小正方体的8个顶点
+    half_size = size / 2
+    vertices = (
+        (x + half_size, y - half_size, z - half_size),  # 右下后
+        (x + half_size, y + half_size, z - half_size),  # 右上后
+        (x - half_size, y + half_size, z - half_size),  # 左上后
+        (x - half_size, y - half_size, z - half_size),  # 左下后
+        (x + half_size, y - half_size, z + half_size),  # 右下前
+        (x + half_size, y + half_size, z + half_size),  # 右上前
+        (x - half_size, y - half_size, z + half_size),  # 左下前
+        (x - half_size, y + half_size, z + half_size)   # 左上前
+    )
+
+    # 定义6个面
+    surfaces = (
+        (0, 1, 2, 3),  # 后面
+        (4, 5, 7, 6),  # 前面
+        (0, 4, 6, 3),  # 底面
+        (1, 5, 7, 2),  # 顶面
+        (0, 1, 5, 4),  # 右面
+        (2, 3, 6, 7)   # 左面
+    )
+
+    # 设置透明度
+    glEnable(GL_BLEND)
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+    # 绘制每个面
+    for surface in surfaces:
+        glBegin(GL_QUADS)
+        glColor4f(1.0, 1.0, 0.0, 0.3)  # 黄色,30%透明度
+        for vertex in surface:
+            glVertex3fv(vertices[vertex])
+        glEnd()
+    
+    # 在小正方体上方绘制编号文本
+    draw_text_at_position(str(cube_number), (x, y, z + size/2 + 0.05))  # 在小正方体顶部稍高处显示编号
+
+def hsv_to_rgb(h, s, v):
+    """将HSV颜色值转换为RGB颜色值
+    h: 色相 (0-1)
+    s: 饱和度 (0-1)
+    v: 明度 (0-1)
+    返回: RGB元组 (r, g, b),每个值在0-1之间
+    """
+    if s == 0.0:
+        return v, v, v
+    
+    i = int(h * 6)
+    f = (h * 6) - i
+    p = v * (1 - s)
+    q = v * (1 - s * f)
+    t = v * (1 - s * (1 - f))
+    
+    i %= 6
+    if i == 0:
+        return v, t, p
+    if i == 1:
+        return q, v, p
+    if i == 2:
+        return p, v, t
+    if i == 3:
+        return p, q, v
+    if i == 4:
+        return t, p, v
+    if i == 5:
+        return v, p, q
+
+def draw_number_labels(screen, small_cube_positions):
+    """在屏幕角落绘制编号标签"""
+    pygame.font.init()
+    font = pygame.font.SysFont('arial', 16)
+    
+    # 绘制编号列表
+    for i, pos in enumerate(small_cube_positions):
+        num = i + 1
+        text = f"#{num}: ({pos[0]:.2f}, {pos[1]:.2f}, {pos[2]:.2f})"
+        text_surface = font.render(text, True, (255, 255, 255))  # 白色文字
+        # 在屏幕左上角垂直排列显示
+        screen.blit(text_surface, (10, 10 + i * 20))
+        
+        # 如果标签太多,限制显示数量
+        if i >= 19:  # 只显示前20个,避免超出屏幕
+            text_surface = font.render("...", True, (255, 255, 255))
+            screen.blit(text_surface, (10, 10 + 20 * 20))
+            break
+
+def main():
+    # 内部小正方体每条边的数量(完全立方数:inner_cube^3个小正方体)
+    inner_cube = 4  # 当前为2,总共2^3=8个小正方体
+    
+    pygame.init()
+    display = (800, 600)
+    screen = pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
+
+    pygame.display.set_caption("透明3D正方体与内部小正方体")
+
+    gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
+    glTranslatef(0.0, 0.0, -5)
+
+    # 启用深度测试
+    glEnable(GL_DEPTH_TEST)
+
+    clock = pygame.time.Clock()
+    
+    while True:
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT:
+                pygame.quit()
+                return
+
+        # 清除颜色和深度缓冲区
+        glClearColor(0.0, 0.0, 0.0, 1.0)  # 黑色背景
+        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+
+        # 旋转整个场景(非常非常缓慢)
+        glRotatef(0.1, 3, 1, 1)  # 每帧只旋转0.1度,实现非常缓慢的旋转
+
+        # 动态生成小正方体的位置
+        # 根据inner_cube的值,在大正方体内均匀分布小正方体
+        small_cube_positions = []
+        spacing = 2.0 / inner_cube  # 大正方体边长为2(从-1到1),分成inner_cube份
+        
+        for x_idx in range(inner_cube):
+            for y_idx in range(inner_cube):
+                for z_idx in range(inner_cube):
+                    # 计算每个小正方体的中心位置
+                    # 从-1+spacing/2 开始,以spacing为间隔分布
+                    x = -1 + spacing/2 + x_idx * spacing
+                    y = -1 + spacing/2 + y_idx * spacing
+                    z = -1 + spacing/2 + z_idx * spacing
+                    small_cube_positions.append((x, y, z))
+        
+        # 计算小正方体的大小,确保它们不会重叠
+        # 小正方体边长 = spacing * 0.8 (留一些间隙)
+        small_cube_size = min(spacing * 0.8, 0.8)  # 限制最大尺寸
+        
+        # 绘制编号的小正方体
+        for i, pos in enumerate(small_cube_positions):
+            draw_small_cube(pos, i+1, size=small_cube_size)
+
+        # 绘制外部大透明正方体
+        draw_solid_cube()
+        
+        # 最后绘制大正方体的线框以增强视觉效果
+        glColor3f(1.0, 1.0, 1.0)  # 白色线框
+        draw_wire_cube()
+
+        # 切换到2D模式绘制编号标签
+        glDisable(GL_DEPTH_TEST)
+        glMatrixMode(GL_PROJECTION)
+        glPushMatrix()
+        glLoadIdentity()
+        glOrtho(0, 800, 600, 0, -1, 1)  # 设置2D正交投影
+        glMatrixMode(GL_MODELVIEW)
+        glPushMatrix()
+        glLoadIdentity()
+        
+        # 绘制编号标签
+        draw_number_labels(screen, small_cube_positions)
+        
+        # 恢复3D模式
+        glPopMatrix()
+        glMatrixMode(GL_PROJECTION)
+        glPopMatrix()
+        glEnable(GL_DEPTH_TEST)
+
+        pygame.display.flip()
+        clock.tick(60)
+
+if __name__ == "__main__":
+    main()

+ 190 - 11
src/yuan.py

@@ -1,5 +1,6 @@
 import pygame
 import math
+import os
 from pygame.locals import *
 from OpenGL.GL import *
 from OpenGL.GLU import *
@@ -32,10 +33,45 @@ def setup_opengl(width, height):
     glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.8, 0.8, 0.8, 1))
     glLightfv(GL_LIGHT0, GL_SPECULAR, (1, 1, 1, 1))
 
-def draw_sphere(radius, color, slices=30, stacks=30):
+def generate_fibonacci_points_on_sphere(n, radius):
+    """
+    Generate n uniformly distributed points on a sphere using Fibonacci sphere algorithm
+    """
+    points = []
+    phi = math.pi * (3. - math.sqrt(5.))  # Golden angle in radians
+    
+    for i in range(n):
+        y = 1 - (i / float(n - 1)) * 2  # y goes from 1 to -1
+        radius_at_y = math.sqrt(1 - y*y)  # Radius at y
+        
+        theta = phi * i  # Golden angle increment
+        
+        x = math.cos(theta) * radius_at_y
+        z = math.sin(theta) * radius_at_y
+        
+        # Scale to the desired radius
+        points.append((x * radius, y * radius, z * radius))
+    
+    return points
+
+def draw_sphere(radius, color, slices=30, stacks=30, draw_points=False):
     """
     Draw a sphere with specified radius
     radius: radius of the sphere
+    draw_points: whether to draw 88 red points on the sphere surface
+    """
+    # Call the new function with 88 points if draw_points is True
+    if draw_points:
+        draw_sphere_with_n_points(radius, color, 88)
+    else:
+        draw_sphere_with_n_points(radius, color, 0)
+
+def draw_sphere_with_n_points(radius, color, num_points, slices=30, stacks=30):
+    """
+    Draw a sphere with specified radius and a specific number of red points
+    radius: radius of the sphere
+    color: color of the sphere
+    num_points: number of red points to draw on the sphere surface
     """
     glPushMatrix()
     
@@ -85,19 +121,162 @@ def draw_sphere(radius, color, slices=30, stacks=30):
             glVertex3f(x * zr0, y * zr0, z0)
         glEnd()
     
+    # Draw red points on the sphere surface if requested
+    if num_points > 0:
+        # Generate specified number of uniformly distributed points on the sphere
+        points = generate_fibonacci_points_on_sphere(num_points, radius)
+        
+        # Save current material properties and disable lighting for points
+        glDisable(GL_LIGHTING)
+        
+        # Set color to red for points
+        glColor3f(1.0, 0.0, 0.0)  # Red color
+        
+        # Draw points
+        glPointSize(5.0)  # Size of the points
+        glBegin(GL_POINTS)
+        for point in points:
+            glVertex3f(point[0], point[1], point[2])
+        glEnd()
+        
+        # Re-enable lighting
+        glEnable(GL_LIGHTING)
+    
     glPopMatrix()
 
 
-def draw_concentric_spheres():
-    """Draw three concentric spheres (big sphere containing smaller spheres)"""
-    # First sphere (smallest, innermost) - Red (drawn first so it's not obscured)
-    draw_sphere(1.0, (1.0, 0.0, 0.0, 0.4))  # Red with semi-transparency
+# Define directories to exclude from the analysis
+EXCLUDED_DIRS = {
+    'node_modules', '.vscode', '.git', '__pycache__', '.pytest_cache', 
+    '.venv', 'venv', 'env', '.env', 'dist', 'build', '.next', '.nuxt',
+    'target', 'tmp', 'temp', '.idea', '.DS_Store', 'Thumbs.db'
+}
+
+def analyze_directory_structure(root_path, max_depth=10):
+    """
+    Analyze the directory tree and return the depth and folder counts per level
+    Returns a tuple: (max_depth, list of counts per level)
+    """
+    if not os.path.exists(root_path):
+        print(f"Directory does not exist: {root_path}")
+        return 1, [0]  # Return 1 level with 0 items if directory doesn't exist
+    
+    # Initialize a list to hold the count of folders at each level
+    level_counts = []
+    
+    def traverse_directory(path, current_depth=0):
+        if current_depth >= max_depth:
+            return
+        
+        # Ensure the level_counts list has enough elements
+        if len(level_counts) <= current_depth:
+            level_counts.extend([0] * (current_depth + 1 - len(level_counts)))
+        
+        try:
+            # Count only directories in the current directory
+            items = os.listdir(path)
+            
+            # Filter out excluded directories
+            filtered_items = [item for item in items if item not in EXCLUDED_DIRS]
+            
+            # Count only directories (not files)
+            dir_count = 0
+            for item in filtered_items:
+                item_path = os.path.join(path, item)
+                if os.path.isdir(item_path):
+                    dir_count += 1
+            
+            level_counts[current_depth] += dir_count
+            
+            # Recursively traverse subdirectories
+            for item in filtered_items:
+                item_path = os.path.join(path, item)
+                if os.path.isdir(item_path):
+                    traverse_directory(item_path, current_depth + 1)
+        except PermissionError:
+            # Skip directories that can't be accessed
+            pass
+    
+    traverse_directory(root_path)
+    
+    # Return the max depth and the counts per level
+    max_depth_found = len(level_counts) - 1 if level_counts else 0
+    return max_depth_found + 1, level_counts
+
+def draw_concentric_spheres_from_directory():
+    """Draw concentric spheres based on directory tree levels"""
+    root_path = "E:\\agricultural_research_platform"
+    num_levels = analyze_directory_levels(root_path)
+    
+    # Limit the number of spheres to prevent performance issues
+    max_spheres = 5  # Maximum number of spheres to display
+    num_levels = min(num_levels, max_spheres)
+    
+    # Ensure we have at least 1 level
+    num_levels = max(1, num_levels)
+    
+    print(f"Directory has {num_levels} levels (limited to {max_spheres} spheres for performance)")
+    
+    # Draw spheres for each level - from smallest to largest
+    for i in range(num_levels):
+        # Calculate radius based on level (starting from 1.0)
+        radius = (i + 1) * 1.0
+        # White color with 90% transparency
+        draw_sphere(radius, (1.0, 1.0, 1.0, 0.1), draw_points=True)  # White with 90% transparency and points
+
+# Global variables to store the directory analysis results (analyze once at startup)
+NUM_LEVELS = None
+LEVEL_COUNTS = None
+
+def get_directory_info():
+    global NUM_LEVELS, LEVEL_COUNTS
+    if NUM_LEVELS is None or LEVEL_COUNTS is None:
+        root_path = "E:\\agricultural_research_platform"
+        raw_levels, raw_counts = analyze_directory_structure(root_path)
+        
+        # Limit the number of spheres to prevent performance issues
+        max_spheres = 5  # Maximum number of spheres to display
+        NUM_LEVELS = min(raw_levels, max_spheres)
+        
+        # Ensure we have at least 1 level
+        NUM_LEVELS = max(1, NUM_LEVELS)
+        
+        # Take only the counts for the levels we'll display
+        LEVEL_COUNTS = raw_counts[:NUM_LEVELS]
+        
+        print(f"Directory has {raw_levels} levels (limited to {NUM_LEVELS} spheres for performance)")
+        print(f"Items per level: {LEVEL_COUNTS}")
+    
+    return NUM_LEVELS, LEVEL_COUNTS
+
+def draw_concentric_spheres_from_directory():
+    """Draw concentric spheres based on directory tree levels"""
+    num_levels, level_counts = get_directory_info()
+    
+    # Draw a large red point at the origin to represent the root node
+    draw_root_node()
+    
+    # Draw spheres for each level - from smallest to largest
+    for i in range(num_levels):
+        # Calculate radius based on level (starting from 1.0)
+        radius = (i + 1) * 1.0
+        # Number of points based on the count of files/folders at this level
+        num_points = level_counts[i] if i < len(level_counts) else 0
+        # White color with 90% transparency
+        draw_sphere_with_n_points(radius, (1.0, 1.0, 1.0, 0.1), num_points)  # White with 90% transparency and dynamic points
+
+def draw_root_node():
+    """Draw a large red point at the center to represent the root node"""
+    glDisable(GL_LIGHTING)  # Disable lighting to ensure pure red color
+    glColor3f(1.0, 0.0, 0.0)  # Red color
     
-    # Second sphere (medium) - Green 
-    draw_sphere(2.0, (0.0, 1.0, 0.0, 0.3))  # Green with semi-transparency
+    # Draw a large point at the origin (center of all spheres)
+    glPointSize(10.0)  # Larger point size for the root node
+    glBegin(GL_POINTS)
+    glVertex3f(0.0, 0.0, 0.0)  # At the center/origin
+    glEnd()
     
-    # Third sphere (largest, outermost) - Blue
-    draw_sphere(3.0, (0.0, 0.0, 1.0, 0.2))  # Blue with higher transparency
+    glEnable(GL_LIGHTING)  # Re-enable lighting
 
 def main():
     display, width, height = init_pygame()
@@ -149,8 +328,8 @@ def main():
         if auto_rotate:
             glRotatef(pygame.time.get_ticks() * 0.01, 0, 1, 0)
         
-        # Draw the concentric spheres
-        draw_concentric_spheres()
+        # Draw the concentric spheres based on directory levels
+        draw_concentric_spheres_from_directory()
         
         pygame.display.flip()
         clock.tick(60)

+ 180 - 0
src/yuan2.py

@@ -0,0 +1,180 @@
+import pygame
+import random
+import math
+import sys
+
+# 初始化Pygame
+pygame.init()
+
+# 设置窗口大小
+WIDTH, HEIGHT = 800, 800
+screen = pygame.display.set_mode((WIDTH, HEIGHT))
+pygame.display.set_caption("大球内的小球碰撞检测")
+
+# 颜色定义
+WHITE = (255, 255, 255)
+BLACK = (0, 0, 0)
+RED = (255, 0, 0)
+BLUE = (0, 0, 255)
+GREEN = (0, 255, 0)
+COLORS = [
+    (255, 100, 100), (100, 255, 100), (100, 100, 255),
+    (255, 255, 100), (255, 100, 255), (100, 255, 255),
+    (255, 150, 50), (150, 255, 50), (50, 150, 255),
+    (255, 50, 150), (150, 50, 255), (50, 255, 150),
+    (255, 200, 150), (200, 255, 150), (150, 200, 255)
+]
+
+class Ball:
+    def __init__(self, x, y, radius, color):
+        self.x = x
+        self.y = y
+        self.radius = radius
+        self.color = color
+        self.vx = random.uniform(-2, 2)
+        self.vy = random.uniform(-2, 2)
+        
+    def move(self, container_radius, container_x, container_y):
+        # 更新位置
+        self.x += self.vx
+        self.y += self.vy
+        
+        # 检查与大球边界的碰撞
+        distance_from_center = math.sqrt((self.x - container_x)**2 + (self.y - container_y)**2)
+        if distance_from_center + self.radius > container_radius:
+            # 计算反射角度
+            angle = math.atan2(self.y - container_y, self.x - container_x)
+            # 将球移回边界内
+            self.x = container_x + (container_radius - self.radius) * math.cos(angle)
+            self.y = container_y + (container_radius - self.radius) * math.sin(angle)
+            
+            # 反射速度
+            normal_x = (self.x - container_x) / math.sqrt((self.x - container_x)**2 + (self.y - container_y)**2)
+            normal_y = (self.y - container_y) / math.sqrt((self.x - container_x)**2 + (self.y - container_y)**2)
+            
+            dot_product = self.vx * normal_x + self.vy * normal_y
+            self.vx -= 2 * dot_product * normal_x
+            self.vy -= 2 * dot_product * normal_y
+    
+    def draw(self, surface):
+        pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.radius)
+        pygame.draw.circle(surface, BLACK, (int(self.x), int(self.y)), self.radius, 2)
+
+def check_collision(ball1, ball2):
+    # 计算两球之间的距离
+    dx = ball2.x - ball1.x
+    dy = ball2.y - ball1.y
+    distance = math.sqrt(dx**2 + dy**2)
+    
+    # 如果距离小于两球半径之和,则发生碰撞
+    if distance < ball1.radius + ball2.radius:
+        # 计算碰撞后的速度
+        # 单位法向量
+        nx = dx / distance
+        ny = dy / distance
+        
+        # 相对速度
+        dvx = ball2.vx - ball1.vx
+        dvy = ball2.vy - ball1.vy
+        
+        # 相对速度在法线方向上的投影
+        dvn = dvx * nx + dvy * ny
+        
+        # 只有当两球相互靠近时才处理碰撞
+        if dvn < 0:
+            # 碰撞冲量
+            impulse = 2 * dvn / (1/ball1.radius + 1/ball2.radius)
+            
+            # 更新速度
+            ball1.vx += impulse * nx / ball1.radius
+            ball1.vy += impulse * ny / ball1.radius
+            ball2.vx -= impulse * nx / ball2.radius
+            ball2.vy -= impulse * ny / ball2.radius
+            
+            # 分离重叠的小球
+            overlap = (ball1.radius + ball2.radius) - distance
+            separation_x = nx * overlap / 2
+            separation_y = ny * overlap / 2
+            ball1.x -= separation_x
+            ball1.y -= separation_y
+            ball2.x += separation_x
+            ball2.y += separation_y
+
+def main():
+    clock = pygame.time.Clock()
+    
+    # 大球参数
+    container_x, container_y = WIDTH // 2, HEIGHT // 2
+    container_radius = 350
+    
+    # 创建15个小球
+    balls = []
+    ball_radius = 20  # 小球半径
+    
+    # 随机生成小球的位置,确保它们不重叠
+    for i in range(15):
+        placed = False
+        attempts = 0
+        while not placed and attempts < 1000:
+            # 在大球内部随机选择一个位置
+            angle = random.uniform(0, 2 * math.pi)
+            distance = random.uniform(0, container_radius - ball_radius - 10)
+            x = container_x + distance * math.cos(angle)
+            y = container_y + distance * math.sin(angle)
+            
+            # 检查是否与其他球重叠
+            valid_position = True
+            for other_ball in balls:
+                dx = x - other_ball.x
+                dy = y - other_ball.y
+                distance_to_other = math.sqrt(dx**2 + dy**2)
+                if distance_to_other < ball_radius + other_ball.radius:
+                    valid_position = False
+                    break
+            
+            if valid_position:
+                balls.append(Ball(x, y, ball_radius, COLORS[i % len(COLORS)]))
+                placed = True
+            
+            attempts += 1
+        
+        if not placed:
+            print(f"无法放置第 {i+1} 个小球,可能空间不足")
+            break
+    
+    running = True
+    while running:
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT:
+                running = False
+            elif event.type == pygame.KEYDOWN:
+                if event.key == pygame.K_ESCAPE:
+                    running = False
+        
+        # 移动所有小球并检查边界碰撞
+        for ball in balls:
+            ball.move(container_radius, container_x, container_y)
+        
+        # 检查小球之间的碰撞
+        for i in range(len(balls)):
+            for j in range(i + 1, len(balls)):
+                check_collision(balls[i], balls[j])
+        
+        # 绘制
+        screen.fill(WHITE)
+        
+        # 绘制大球边界
+        pygame.draw.circle(screen, BLACK, (container_x, container_y), container_radius, 3)
+        
+        # 绘制所有小球
+        for ball in balls:
+            ball.draw(screen)
+        
+        pygame.display.flip()
+        clock.tick(60)
+    
+    pygame.quit()
+    sys.exit()
+
+if __name__ == "__main__":
+    main()

+ 130 - 0
src/yyy.py

@@ -0,0 +1,130 @@
+import tkinter as tk
+import math
+
+class SquareWindow:
+    def __init__(self):
+        # Create the main window
+        self.root = tk.Tk()
+        self.root.title("Square Window")
+        
+        # Set window size to 1000x1000 pixels
+        self.window_size = 1000
+        self.root.geometry(f"{self.window_size}x{self.window_size}")
+        
+        # Create a canvas to draw on
+        self.canvas = tk.Canvas(self.root, width=self.window_size, height=self.window_size, bg="white")
+        self.canvas.pack(fill=tk.BOTH, expand=True)
+        
+        # Draw the main square (numbered as 0) and all nested squares
+        all_numbers = self.draw_nested_squares(outer_square_num=0, inner_square_count=79)
+        print(f"All square numbers: {all_numbers}")
+    
+    def draw_nested_squares(self, outer_square_num, inner_square_count, x1=None, y1=None, x2=None, y2=None, parent_square_info=None):
+        """
+        Draw nested squares recursively.
+        
+        Args:
+            outer_square_num: The number of the outer square
+            inner_square_count: How many inner squares to draw inside the outer square
+            x1, y1, x2, y2: Coordinates of the outer square (if None, assumes it's the main square)
+            parent_square_info: Information about the parent square for positioning
+        
+        Returns:
+            A list of all square numbers that were drawn
+        """
+        # Calculate the size and position of the outer square
+        if x1 is None or y1 is None or x2 is None or y2 is None:
+            # This is the main outer square (number 0)
+            square_size = int(self.window_size * 0.9)  # 90% of 1000 = 900
+            margin = (self.window_size - square_size) // 2  # (1000 - 900) / 2 = 50
+            x1, y1 = margin, margin
+            x2, y2 = margin + square_size, margin + square_size
+            
+            # Draw the main square and label it
+            self.canvas.create_rectangle(x1, y1, x2, y2, outline="black", width=2)
+            
+            # Add number 0 in the center of the main square
+            center_x = x1 + square_size // 2
+            center_y = y1 + square_size // 2
+            self.canvas.create_text(center_x, center_y, text=str(outer_square_num), fill="black", font=("Arial", 12))
+        else:
+            # This is a nested square, draw it with a different color
+            self.canvas.create_rectangle(x1, y1, x2, y2, outline="gray", width=1)
+            
+            # Add number in the center of the square
+            center_x = x1 + (x2 - x1) // 2
+            center_y = y1 + (y2 - y1) // 2
+            self.canvas.create_text(center_x, center_y, text=str(outer_square_num), fill="black", font=("Arial", 10))
+
+        # Find the closest perfect square that is >= inner_square_count
+        n = math.ceil(math.sqrt(inner_square_count))
+        actual_number = n * n
+        
+        print(f"You wanted {inner_square_count} squares, but we're drawing {actual_number} squares in a {n}x{n} grid for square #{outer_square_num}.")
+        
+        # Calculate the size of each small square (1/n of the main square's side minus 2 pixels)
+        square_width = x2 - x1
+        square_height = y2 - y1
+        small_square_size = min((square_width // n) - 2, (square_height // n) - 2)
+        
+        # Draw the required number of squares (up to inner_square_count) in an n x n grid
+        square_number_base = outer_square_num + 1  # Start numbering after the outer square
+        all_numbers = [outer_square_num]  # Include the outer square number
+        
+        # Calculate spacing to distribute squares evenly with gaps
+        total_used_space = n * small_square_size  # Total space occupied by squares
+        remaining_space_x = square_width - total_used_space  # Remaining space for gaps in x direction
+        remaining_space_y = square_height - total_used_space  # Remaining space for gaps in y direction
+        gap_x = remaining_space_x // (n + 1)  # Gap between squares and margins in x
+        gap_y = remaining_space_y // (n + 1)  # Gap between squares and margins in y
+        
+        for i in range(n):  # Rows
+            for j in range(n):  # Columns
+                current_inner_num = square_number_base + (i * n + j)
+                
+                if current_inner_num > outer_square_num + inner_square_count:
+                    break  # Stop drawing if we've reached the desired number
+                
+                # Calculate position for each small square with proper spacing
+                small_x = x1 + gap_x + j * (small_square_size + gap_x)
+                small_y = y1 + gap_y + i * (small_square_size + gap_y)
+                
+                # Draw the small square
+                self.canvas.create_rectangle(
+                    small_x, small_y, 
+                    small_x + small_square_size, small_y + small_square_size,
+                    outline="blue", width=1
+                )
+                
+                # Add number in the center of each small square
+                center_x = small_x + small_square_size // 2
+                center_y = small_y + small_square_size // 2
+                self.canvas.create_text(center_x, center_y, text=str(current_inner_num), fill="red", font=("Arial", 10))
+                
+                # If this is the 2nd square in the main grid, draw 7 smaller squares inside it
+                if outer_square_num == 0 and current_inner_num == 2:
+                    # Recursively call to draw 7 squares inside this square
+                    inner_squares = self.draw_nested_squares(
+                        outer_square_num=current_inner_num,
+                        inner_square_count=7,
+                        x1=small_x,
+                        y1=small_y,
+                        x2=small_x + small_square_size,
+                        y2=small_y + small_square_size
+                    )
+                    all_numbers.extend(inner_squares)
+                
+                # Add the current square number to the list
+                all_numbers.append(current_inner_num)
+                
+            if current_inner_num > outer_square_num + inner_square_count:
+                break  # Break outer loop as well if we've reached the desired number
+        
+        return all_numbers
+    
+    def run(self):
+        self.root.mainloop()
+
+if __name__ == "__main__":
+    app = SquareWindow()
+    app.run()