############################## ### DM2_w24 hu_03_setUp ### ### _diag / 2024 10 17 ### ############################## import rhinoscriptsyntax as rs import random, time, sys ### import random, math, sys ### sys.path.append("P:/WWW/bobbycar123") ### add path where "DM_lib.py" can be found !!! import DM_lib as dm ### reload(dm) ############################## # Setup der Rhino-Umgebung rs.UnitSystem(3) rs.ShowGrid(view=None, show=1) rs.ShowGridAxes(view=None, show=1) rs.ViewDisplayMode(view=None, mode="Wireframe") rs.EnableRedraw(0) dm.PointRadius(displayModeX=0, rad=3, styl=1) rs.DeleteObjects(rs.AllObjects()) dm.newEmptyLayer("HU04::lines", [100, 255, 20]) dm.newEmptyLayer("HU04::spherePoints", [200, 200, 111]) dm.newEmptyLayer("HU04::points", [255, 0, 0]) rs.EnableRedraw(0) dm.eA() rs.Redraw() dm.PointRadius(displayModeX=1, rad=2, styl=1, verbose=1) dm.PointRadius(displayModeX=0, rad=3, styl=2, verbose=1) # Funktion zum Erstellen von Quaderpunkten (Podest) def create_cube_points(origin, size, num_points): points = [] for _ in range(num_points): x = origin[0] + random.uniform(-size / 2, size / 2) y = origin[1] + random.uniform(-size / 2, size / 2) z = origin[2] + random.uniform(-size / 2, size / 2) points.append([x, y, z]) return points # Funktion zum Erstellen unterschiedlicher Punktgroessen und Farben def assign_random_size_color(points): for point in points: size = random.uniform(500, 1000) # Zufaellige Groesse zwischen 500 und 1000 color = [random.randint(10, 255), random.randint(0, 255), random.randint(0, 255)] # Zufaellige Farbe rs.AddPoint(point) rs.ObjectColor(rs.AddPoint(point), color) rs.ObjectLayer(rs.AddPoint(point), "HU04::points") rs.ObjectName(rs.AddPoint(point), "size{}".format(size)) # Pilzstiel (Zylinder) def create_cylinder(center, radius, height, num_points): points = [] for i in range(num_points): angle = 2 * math.pi * i / num_points x = center[0] + radius * math.cos(angle) y = center[1] + radius * math.sin(angle) z = center[2] points.append([x, y, z]) points.append([x, y, z + height]) return points # Pilzhut (Kreis oben) def create_cap(center, radius, num_points): points = [] for i in range(num_points): angle = 2 * math.pi * i / num_points x = center[0] + radius * math.cos(angle) y = center[1] + radius * math.sin(angle) z = center[2] points.append([x, y, z]) return points # Schwebender Halbkreis def create_half_circle(center, radius, num_points, height): points = [] for i in range(num_points // 2): angle = math.pi * i / (num_points // 2 - 1) x = center[0] + radius * math.cos(angle) y = center[1] + radius * math.sin(angle) z = center[2] + height points.append([x, y, z]) return points # Schwebende Halbkugel def create_half_sphere(center, radius, num_points, height): points = [] for i in range(num_points): phi = math.pi * (i / num_points) for j in range(num_points): theta = 2 * math.pi * (j / num_points) x = center[0] + radius * math.sin(phi) * math.cos(theta) y = center[1] + radius * math.sin(phi) * math.sin(theta) z = center[2] + radius * math.cos(phi) + height points.append([x, y, z]) return points # Erstellen des Podests podest_center = [0, 0, -10] podest_size = 20 num_podest_points = 500 # Mehr Punkte im Quader podest_points = create_cube_points(podest_center, podest_size, num_podest_points) # Erstellen des Pilzstiels cylinder_center = [0, 0, 0] cylinder_radius = 5 cylinder_height = 20 num_cylinder_points = 1000 cylinder_points = create_cylinder(cylinder_center, cylinder_radius, cylinder_height, num_cylinder_points) # Erstellen des Pilzhuts cap_center = [0, 0, cylinder_height] cap_radius = 10 num_cap_points = 100 cap_points = create_cap(cap_center, cap_radius, num_cap_points) # Erstellen des schwebenden Halbkreises half_circle_center = [0, 0, cylinder_height + 10] half_circle_radius = 15 num_half_circle_points = 100 half_circle_points = create_half_circle(half_circle_center, half_circle_radius, num_half_circle_points, 10) # Erstellen der schwebenden Halbkugel half_sphere_center = [0, 0, cylinder_height + 10] half_sphere_radius = 20 num_half_sphere_points = 40 half_sphere_points = create_half_sphere(half_sphere_center, half_sphere_radius, num_half_sphere_points, 10) # Hinzufuegen der Punkte in Rhino podest_objs = rs.AddPoints(podest_points) cylinder_objs = rs.AddPoints(cylinder_points) cap_objs = rs.AddPoints(cap_points) half_circle_objs = rs.AddPoints(half_circle_points) half_sphere_objs = rs.AddPoints(half_sphere_points) # Zufaellige Groessen und Farben zuweisen assign_random_size_color(podest_points) assign_random_size_color(half_sphere_points) # Fuer die Kugel auch anwenden # Verbinden der Punkte mit Linien lines = [] # Linien innerhalb des Podests for i in range(len(podest_points) - 1): for j in range(i + 1, len(podest_points)): lines.append(rs.AddLine(podest_points[i], podest_points[j])) # Linien zwischen Podest und Pilzstiel for pod_point in podest_points: for cyl_point in cylinder_points: lines.append(rs.AddLine(pod_point, cyl_point)) # Linien innerhalb des Pilzes for i in range(0, len(cylinder_points), 2): bottom_point = cylinder_points[i] top_point = cylinder_points[i + 1] lines.append(rs.AddLine(bottom_point, top_point)) # Verbinden der Pilzhutpunkte mit Pilzstielpunkten #for cap_point in cap_points: # for i in range(0, len(cylinder_points), 2): # lines.append(rs.AddLine(cap_point, cylinder_points[i + 1])) # Verbinden der Halbkreispunkte mit Pilzhutpunkten for half_circle_point in half_circle_points: for cap_point in cap_points: lines.append(rs.AddLine(half_circle_point, cap_point)) # Verbinden der Halbkugelpunkte mit Pilzhutpunkten for half_sphere_point in half_sphere_points: for cap_point in cap_points: lines.append(rs.AddLine(half_sphere_point, cap_point)) # Anwenden des Farbverlaufs def apply_gradient_color(objects, start_color, end_color): num_objects = len(objects) for i, obj in enumerate(objects): ratio = i / (num_objects - 1) r = start_color[0] + ratio * (end_color[0] - start_color[0]) g = start_color[1] + ratio * (end_color[1] - start_color[1]) b = start_color[2] + ratio * (end_color[2] - start_color[2]) rs.ObjectColor(obj, [r, g, b]) apply_gradient_color(podest_objs + cylinder_objs + cap_objs + half_circle_objs + half_sphere_objs + lines, [255, 165, 0], [75, 0, 130]) # Zeichnen aktivieren rs.EnableRedraw(1)