################################################################################ import rhinoscriptsyntax as rs import random as rd import sys sys.path.append("P:\\WWW\\mraontu\\dm2") #"P:/" import DM_lib as dm #reload(dm) for lay in rs.LayerNames(): rs.PurgeLayer(lay) # neuen layer / view setup dm.newEmptyLayer("hu_04_gr2_manuel", color=[0, 0, 0]) rs.ShowGrid(view="Perspective", show=0) rs.ShowGridAxes(view="Perspective", show=0) rs.ViewDisplayMode(view="Perspective", mode=None) rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) ################################################################################ ### Parameter Spiralen spiral_size = rd.randint(10,40) # z size z_scale_factor = 10 anz_spiral = rd.randint(30,60) # Anzahl pts spirale num_turns = rd.randint(1,4) # Windungen radius = spiral_size * rd.randint(1,3) ### Parameter Kugel rad = rd.uniform(0.4,1) # Kugelradius vec = [rad, 0, 0] anz = rd.randint(20,80) # Anzahl pts Kugeln deltaAngle = 360 / anz # Rotationswinkel rot = [255, 0, 0] blau = [0, 0, 255] vecX = [radius, 0, 0] vecY = [-radius, 0, 0] spiral_points_1 = [] spiral_points_2 = [] ### Spirale Rot for i in range(anz_spiral): angle = (360 / anz_spiral) * num_turns * i rotated_vecX = rs.VectorRotate(vecX, angle, [0, 0, 1]) # rotiert vec um z achse z_shift = (i / float(anz_spiral)) * spiral_size * z_scale_factor # verschiebet den vec entlang Z Achse rotated_vecX[2] = z_shift spiral_points_1.append(rotated_vecX) point_Rot = rs.AddPoint(rotated_vecX) rs.ObjectColor(point_Rot, rot) ### Spirale Blau for i in range(anz_spiral): angle = (360 / anz_spiral) * num_turns * i rotated_vecY = rs.VectorRotate(vecY, angle, [0, 0, 1]) # rotiert vec um z achse z_shift = (i / float(anz_spiral)) * spiral_size * z_scale_factor # verschiebet den vec entlang Z Achse rotated_vecY[2] = z_shift spiral_points_2.append(rotated_vecY) point_Blau = rs.AddPoint(rotated_vecY) rs.ObjectColor(point_Blau, blau) ### Verbindungen crvs, pts # start copy of chat gpt def interpolate_color(start_color, end_color, t): return [int(start_color[i] + t * (end_color[i] - start_color[i])) for i in range(3)] #Farbverlauf ChatGPT # end copy of chat gpt num_div = 5 div_points = [] for i in range(len(spiral_points_1)): start = spiral_points_1[i] end = spiral_points_2[i] line_id = rs.AddLine(start,end) #start copy of chat gpt for j in range(num_div + 1): t = j / float(num_div) # Normalisiere den Interpolationsfaktor color = interpolate_color([255, 0, 0], [0, 0, 255], t) # Farbverlauf von Rot zu Blau # Berechne den Punkt entlang der Linie inter_point = [(1 - t) * start[k] + t * end[k] for k in range(3)] point_id = rs.AddPoint(inter_point) rs.ObjectColor(point_id, color) # Wende die interpolierte Farbe an # end copy of chat gpt #rs.ObjectColor(line_id, [0, 255, 0]) # Farbe Gruen #division_pts = rs.DivideCurve(line_id, num_div, 0) #div_points.extend(division_pts) #pts = rs.AddPoints(div_points) #rs.ObjectColor(pts, [0, 255, 0]) ######################### Kugel vector pts UE3 ################################# for spiral_point_rot in spiral_points_1: for i in range(anz): rotation_axis = [rd.uniform(-1, 1), rd.uniform(-1, 1), rd.uniform(-1, 1)] vecKugel = rs.VectorRotate(vec, deltaAngle * i, rotation_axis) vecKugel = rs.VectorUnitize(vecKugel) vecKugel = rs.VectorScale(vecKugel, rad*10) vecKugel = rs.VectorAdd(vecKugel, spiral_point_rot) pts_kugel = rs.AddPoint(vecKugel) rs.ObjectColor(pts_kugel, rot) for spiral_point_blau in spiral_points_2: for i in range(anz): rotation_axis = [rd.uniform(-1, 1), rd.uniform(-1, 1), rd.uniform(-1, 1)] vecKugel = rs.VectorRotate(vec, deltaAngle * i, rotation_axis) vecKugel = rs.VectorUnitize(vecKugel) vecKugel = rs.VectorScale(vecKugel, rad*10) vecKugel = rs.VectorAdd(vecKugel, spiral_point_blau) pts_kugel = rs.AddPoint(vecKugel) rs.ObjectColor(pts_kugel, blau) ### Draw Curves Spirale #rs.AddPolyline(spiral_points_1) #rs.AddPolyline(spiral_points_2) crv_rot = rs.AddCurve (spiral_points_1,1) rs.ObjectColor ( crv_rot, rot ) crv_blau = rs.AddCurve (spiral_points_2,1) rs.ObjectColor ( crv_blau, blau) dm.PointRadius(displayModeX=0, rad=3, styl=1) rs.EnableRedraw(True) rs.ZoomExtents() dm.newEmptyLayer("Default", color=[0, 0, 0]) print "Windungen =", num_turns print "Anzahl pts Spirale =", anz_spiral print "Anzahl pts Kugeln =", anz print "Radius Spriale = ", radius print "Radius der Kugeln ", rad print "fin hu_04 Manuel"