import rhinoscriptsyntax as rs import random, sys, math sys.path.append("P:/WWW/arhitekt0811/DM2") import DM_lib as dm rs.EnableRedraw(False) dm.eA() def random_color(): return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) def addiere_cubus(center, size, anzahl_points=500, randomness=0.0, linien_dichte=0.5): cubus_coords = [] for _ in range(anzahl_points): x = random.uniform(center[0] - size / 2, center[0] + size / 2) y = random.uniform(center[1] - size / 2, center[1] + size / 2) z = random.uniform(center[2] - size / 2, center[2] + size / 2) x += random.uniform(-randomness, randomness) y += random.uniform(-randomness, randomness) z += random.uniform(-randomness, randomness) cubus_coords.append([x, y, z]) cubus_points = rs.AddPoints(cubus_coords) random_col = random_color() rs.ObjectColor(cubus_points, random_col) if len(cubus_coords) > 1: num_lines = max(5, int(len(cubus_coords) * linien_dichte)) selected_indices = random.sample(range(len(cubus_coords)), min(num_lines, len(cubus_coords))) for i in range(len(selected_indices) - 1): rs.AddCurve([cubus_coords[selected_indices[i]], cubus_coords[selected_indices[i + 1]]], 1) return cubus_points def zufaelliger_punkt_in_kugel(radius): u = random.uniform(0, 1) v = random.uniform(0, 1) theta = 2 * math.pi * u # Winkel phi = math.acos(2 * v - 1) # Neigung r = radius * (random.uniform(0, 3) ** (1/3)) # Koordinaten umwandeln x = r * math.sin(phi) * math.cos(theta) y = r * math.sin(phi) * math.sin(theta) z = r * math.cos(phi) return [x, y, z] kugel_radius = 50 kugel_center = [0, 0, 0] anzahl_kugel_points = 2000 kugel_points = [] for _ in range(anzahl_kugel_points): zufaelliger_punkt = zufaelliger_punkt_in_kugel(kugel_radius) kugel_points.append(rs.AddPoint(rs.PointAdd(kugel_center, zufaelliger_punkt))) # Cubus 1 cubus_size1 = random.randint(15, 35) anzahl_points1 = 400 randomness1 = 0.2 linien_dichte1 = 0.2 addiere_cubus(zufaelliger_punkt_in_kugel(kugel_radius - cubus_size1), cubus_size1, anzahl_points1, randomness1, linien_dichte1) # Cubus 2 cubus_size2 = random.randint(20, 40) anzahl_points2 = 250 randomness2 = 0.2 linien_dichte2 = 0.8 # Dichte der Linien addiere_cubus(zufaelliger_punkt_in_kugel(kugel_radius - cubus_size2), cubus_size2, anzahl_points2, randomness2, linien_dichte2) rs.EnableRedraw(True)