#DM2_w24 hu_04_setUp# import rhinoscriptsyntax as rs import random, time, sys ### sys.path.append("P:/WWW/cherrycola/DM2") import DM_lib as dm ### reload(dm) ############################## import rhinoscriptsyntax as rs import math # Clean up the workspace rs.DeleteObjects(rs.AllObjects()) # Define colors sphere_color = [255, 0, 0] # Red for the sphere cube_color_start = [128, 0, 128] # Dark purple cube_color_end = [255, 128, 255] # Light purple # Sphere properties (slightly larger) sphere_center = [10, 10, 10] sphere_radius = 12 # Increased radius # Cube properties cube_base_point = [0, 0, 0] cube_size = 20 line_spacing = 2 # Spacing between lines inside the cube # Function to calculate gradient color def interpolate_color(start_color, end_color, factor): return [ start_color[i] + (end_color[i] - start_color[i]) * factor for i in range(3) ] # Function to check if a point is inside the sphere def is_inside_sphere(point, center, radius): distance = math.sqrt( (point[0] - center[0]) ** 2 + (point[1] - center[1]) ** 2 + (point[2] - center[2]) ** 2 ) return distance < radius # Create the sphere as a volume of points sphere_points = [] for x in range(-sphere_radius, sphere_radius + 1): for y in range(-sphere_radius, sphere_radius + 1): for z in range(-sphere_radius, sphere_radius + 1): pt = [sphere_center[0] + x, sphere_center[1] + y, sphere_center[2] + z] if is_inside_sphere(pt, sphere_center, sphere_radius): sphere_points.append(pt) # Add the points to Rhino sphere_points_id = rs.AddPoints(sphere_points) rs.ObjectColor(sphere_points_id, sphere_color) # Create the cube with horizontal lines only cube_lines = [] for z in range(0, cube_size + 1, line_spacing): for y in range(0, cube_size + 1, line_spacing): pt1 = [cube_base_point[0], cube_base_point[1] + y, cube_base_point[2] + z] pt2 = [cube_base_point[0] + cube_size, cube_base_point[1] + y, cube_base_point[2] + z] if not (is_inside_sphere(pt1, sphere_center, sphere_radius) or is_inside_sphere(pt2, sphere_center, sphere_radius)): cube_lines.append(rs.AddLine(pt1, pt2)) # Apply gradient colors to cube lines total_lines = len(cube_lines) for i, line in enumerate(cube_lines): factor = i / total_lines # Calculate the gradient factor color = interpolate_color(cube_color_start, cube_color_end, factor) rs.ObjectColor(line, color) rs.ZoomExtents()