import rhinoscriptsyntax as rs import random import math import scriptcontext rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) max_pts = 2000 min_pts = 0 range_x = 100 range_y = 100 range_z = 100 crv_controlpts = 5 crv_degree = 2 pipe_thick = 0.4 pipe_thinn = 0.15 num_smaller_spheres = 12 min_smaller_radius = 0.1 max_smaller_radius = 0.3 sphere_offset = 0.5 min_radius = 0.3 max_radius = 1.0 spike_height = 2.0 spike_radius = 0.2 spike_count = 5 def placePt(x_range, y_range, z_range): x = random.uniform(0, x_range) y = random.uniform(0, y_range) z = random.uniform(0, z_range) pt = (x, y, z) return pt ptZero = (0, 0, 0) pts = [] pts.append(ptZero) mlines = [] for i in range(min_pts, max_pts): pt = rs.AddPoint(placePt(range_x, range_y, range_z)) index = rs.PointArrayClosestPoint(pts, pt) cp = pts[index] vect = rs.VectorCreate(cp, pt) unitVect = rs.VectorUnitize(vect) subVect = vect - unitVect newPt = rs.MoveObject(pt, subVect) pts.append(newPt) mlines.append(rs.AddInterpCurve([cp, newPt])) """ def placePt(x_range, y_range, z_range): x = random.uniform(0, x_range) y = random.uniform(0, y_range) z = random.uniform(0, z_range) pt = (x, y, z) return pt mlines = [] for i in range(min_pts, max_pts): pt = rs.AddPoint(placePt(-100, -100, -100)) index = rs.PointArrayClosestPoint(pts, pt) cp = pts[index] vect = rs.VectorCreate(cp, pt) unitVect = rs.VectorUnitize(vect) subVect = vect - unitVect newPt = rs.MoveObject(pt, subVect) pts.append(newPt) mlines.append(rs.AddInterpCurve([cp, newPt])) """ jlines = rs.JoinCurves(mlines) rebuild_curves = [] for crv in jlines: rebuilt_curve = rs.RebuildCurve(crv, crv_controlpts, crv_degree) if rebuilt_curve: rebuild_curves.append(rebuilt_curve) Pipe = "PipesLayer" if not rs.IsLayer(Pipe): rs.AddLayer(Pipe) pipesrf = [] for crv in jlines: pipe = rs.AddPipe(crv, [0, 1], [pipe_thick, pipe_thinn], cap = 2) if pipe: rs.ObjectLayer(pipe, Pipe) pipesrf.append(pipe) Sphere = "SpheresLayer" if not rs.IsLayer(Sphere): rs.AddLayer(Sphere) for crv in jlines: end_point = rs.CurveEndPoint(crv) radius = random.uniform(min_radius, max_radius) sphere = rs.AddSphere(end_point, radius) if sphere: rs.ObjectLayer(sphere, Sphere) for crv in jlines: end_point = rs.CurveEndPoint(crv) radius = random.uniform(min_radius, max_radius) sphere = rs.AddSphere(end_point, radius) if sphere: rs.ObjectLayer(sphere, Sphere) for _ in range(num_smaller_spheres): theta = random.uniform(0, 2 * math.pi) phi = random.uniform(0, math.pi) x = end_point[0] + sphere_offset * math.sin(phi) * math.cos(theta) y = end_point[1] + sphere_offset * math.sin(phi) * math.sin(theta) z = end_point[2] + sphere_offset * math.cos(phi) smaller_radius = random.uniform(min_smaller_radius, max_smaller_radius) smaller_sphere = rs.AddSphere((x, y, z), smaller_radius) if smaller_sphere: rs.ObjectLayer(smaller_sphere, Sphere) """ Spikes = "SpikesLayer" if not rs.IsLayer(Spikes): rs.AddLayer(Spikes) Spikes out of the Spheres for crv in jlines: division_points = rs.DivideCurve(crv, spike_count) for pt in division_points: if pt: random_direction = rs.VectorCreate((random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1)), (0, 0, 0)) random_direction = rs.VectorUnitize(random_direction) plane = rs.PlaneFromNormal(pt, random_direction) spike = rs.AddCone(plane, spike_height, spike_radius) if spike: rs.ObjectLayer(spike, Spikes) """ """ for crv in jlines: end_point = rs.CurveEndPoint(crv) radius = random.uniform(0.5, 2.0) sphere = rs.AddSphere(end_point, radius) if sphere: rs.ObjectLayer(sphere, Sphere) ran_crv = "RandomCurvesLayer" if not rs.IsLayer(ran_crv): rs.AddLayer(ran_crv) random_curve_count = 2 for crv in jlines: division_points = rs.DivideCurve(crv, random_curve_count) for pt in division_points: if pt: random_points = [] for _ in range(3): random_offset_x = random.uniform(-5, 5) random_offset_y = random.uniform(-5, 5) random_offset_z = random.uniform(-5, 5) random_point = rs.PointAdd(pt, (random_offset_x, random_offset_y, random_offset_z)) random_points.append(random_point) random_curve = rs.AddInterpCurve(random_points) if random_curve: rs.ObjectLayer(random_curve, ran_crv) for random_curve in rs.AllObjects(): if rs.ObjectLayer(random_curve) == ran_crv: pipe = rs.AddPipe(random_curve, [0, 1], [0.2, 0.15], cap=2) if pipe: rs.ObjectLayer(pipe, Pipe) """