import rhinoscriptsyntax as rs import random def delete_previous_objects(): """ Deletes all existing objects in the Rhino document. """ objects = rs.AllObjects() if objects: rs.DeleteObjects(objects) def create_dome_with_cubes(radius=20, rows=30, cols=30, max_cube_height=5): """ Creates a dome-like structure with cubes arranged on a grid. Parameters: radius (float): Radius of the dome. rows (int): Number of rows in the grid. cols (int): Number of columns in the grid. max_cube_height (float): Maximum height of the cubes. """ for i in range(rows): for j in range(cols): # Calculate the grid position x = i - rows / 2 y = j - cols / 2 distance_from_center = (x**2 + y**2)**0.5 # Check if the point lies within the dome's radius if distance_from_center <= radius: # Calculate the dome height at this point dome_height = (radius**2 - distance_from_center**2)**0.5 # Add randomness to the cube height cube_height = random.uniform(0.5, max_cube_height) # Calculate the cube base point base_point = (x, y, dome_height - cube_height / 2) # Create the cube create_cube(base_point, 1, cube_height) def create_cube(base_point, size, height): """ Creates a cube given its base point, size, and height. Parameters: base_point (tuple): The (x, y, z) coordinates of the cube's base center. size (float): The width and depth of the cube. height (float): The height of the cube. """ x, y, z = base_point half_size = size / 2 vertices = [ (x - half_size, y - half_size, z), (x + half_size, y - half_size, z), (x + half_size, y + half_size, z), (x - half_size, y + half_size, z), (x - half_size, y - half_size, z + height), (x + half_size, y - half_size, z + height), (x + half_size, y + half_size, z + height), (x - half_size, y + half_size, z + height) ] # Create the cube as a polyline and extrude bottom_face = rs.AddPolyline(vertices[:4] + [vertices[0]]) rs.AddBox(vertices) rs.DeleteObject(bottom_face) # Run the script delete_previous_objects() create_dome_with_cubes(radius=20, rows=30, cols=30, max_cube_height=5)