############################## import rhinoscriptsyntax as rs import math import random import sys sys.path.append("/Users/anny.more/Documents/studium/5. semester/DM2") sys.path.append("P:/") import DM_lib as dm ############################## ##################### colours colors = [(255, 105, 180), # pink for Sphere (34, 139, 34), # green for Cube 1 (0, 0, 139), # blue for Cube 2 (205, 133, 63), # brown for Cube 3 (255, 160, 122), # orange for Cube 4 (186, 85, 211)] # lilac for Cube 5 curve_color = (169, 169, 169) # gray for curves connecting the cubes ##################### main sphere if 1: anz = 2000 # Number of points rad = 500.0 # radius of the sphere elevation = 1000 # Elevation above the origin center = [0, 0, elevation] # center of Sphere higher up on z-Axis sphere_points = [] for i in range(anz): theta = math.acos(1 - 2 * (i + 0.5) / anz) phi = math.pi * (1 + 5**0.5) * i x = rad * math.sin(theta) * math.cos(phi) y = rad * math.sin(theta) * math.sin(phi) z = rad * math.cos(theta) pt = rs.AddPoint(rs.VectorAdd(center, [x, y, z])) sphere_points.append(pt) for pt in sphere_points: rs.ObjectColor(pt, colors[0]) ##################### cubes in a circle cube_size = 500 num_points_per_side = 10 # Number of points per side cube_radius = 1500 # Radius of the circle in which cubes are arranged angle_increment = 2 * math.pi / 5 # Angle increment for placing cubes in a circle cubes_points_list = [] # List to store all points from all cubes for i in range(5): angle = i * angle_increment cube_center_x = cube_radius * math.cos(angle) cube_center_y = cube_radius * math.sin(angle) cube_corner = [cube_center_x - cube_size / 2, cube_center_y - cube_size / 2, elevation - cube_size / 2] cube_points = [] step = cube_size / (num_points_per_side - 1) # Step size for points on each edge for x in range(num_points_per_side): for y in range(num_points_per_side): for z in range(num_points_per_side): pt_x = cube_corner[0] + x * step pt_y = cube_corner[1] + y * step pt_z = cube_corner[2] + z * step if (x == 0 or x == num_points_per_side - 1 or y == 0 or y == num_points_per_side - 1 or z == 0 or z == num_points_per_side - 1): pt = rs.AddPoint([pt_x, pt_y, pt_z]) cube_points.append(pt) rs.ObjectColor(cube_points, colors[i + 1]) cubes_points_list.append(cube_points) ##################### reduced curves between neighboring cubes if 1: for j in range(5): current_cube_points = cubes_points_list[j] next_cube_points = cubes_points_list[(j + 1) % 5] # Connect 50 points between neighboring cubes for k in range(50): # Half the number of curves between each pair of neighboring cubes pt1 = rs.coerce3dpoint(current_cube_points[random.randint(0, len(current_cube_points) - 1)]) pt2 = rs.coerce3dpoint(next_cube_points[random.randint(0, len(next_cube_points) - 1)]) if pt1 and pt2: curve = rs.AddCurve([pt1, pt2]) rs.ObjectColor(curve, curve_color) ##################### curves from cubes to sphere without crossing if 1: for i, cube_points in enumerate(cubes_points_list): angle = i * angle_increment target_x = rad * math.cos(angle) target_y = rad * math.sin(angle) target_z = elevation sphere_point = rs.AddPoint([target_x, target_y, target_z]) for _ in range(10): # Create ten curves pt_cube = rs.coerce3dpoint(cube_points[random.randint(0, len(cube_points) - 1)]) if pt_cube and sphere_point: rs.AddCurve([pt_cube, sphere_point])