########################## import rhinoscriptsyntax as rs import random as rd import random, time, sys sys.path.append("P:\WWW\mraontu\dm2") import DM_lib as dm reload(dm) ########################## rs.ShowGrid(view=None, show=0) rs.ShowGridAxes(view=None, show=0) rs.ViewDisplayMode(view=None, mode="wireframe") #rs.EnableRedraw(0) allObj = rs.AllObjects() rs.DeleteObjects(allObj) dm.newEmptyLayer("HU_02") rs.LayerColor("HU_02", [0, 0, 0]) for lay in rs.LayerNames(): rs.PurgeLayer(lay) ###points 3D grid/cube coords = [] ### liste fuer pts anzahl = rd.randint(18,24) ### anzahl pts entlang jeder achse xVal = rd.uniform(1.5,2) ### rd.uniform(1,2) yVal = rd.uniform(1.5,2) ### abstand von pt zu pt zVal = rd.uniform(1.5,3) # rd.uniform(1,2) gibt auch rationale Zahlen; round(rd.uniform(1,4),0) # rd.randint(2,8) gibt nur ganze Zahlen; mit Grenzwerte # xyzVal = [xVal, yVal, zVal] # minVal = min(xyzVal) # maxVal = max(xyzVal) for i in range(anzahl): ### for schleifen, punkte erzeugen for j in range(anzahl): for k in range(anzahl): cor = [i*xVal, j*yVal, k*zVal ] ### koordinaten berechnen (0.(0,0,0), 1.(0,0,1), 2.(0,1,0), 3.(0,1,1) ...) coords.append( cor ) ### pts in liste einfuegen rs.AddPoints(coords) #dm.textDots(coords) ############################################# ### Kugel ausschneiden hole_radius = anzahl * rd.uniform(0.9,1.3) #hole_radius = anzahl * maxVal center = [(anzahl - 1) * xVal / 2, (anzahl - 1) * yVal / 2, (anzahl - 1) * zVal / 2] ### center pt; anzahl - 1 weil Start bei 0. in liste coords_with_hole = [] ### neue liste der Koordinaten mit Loch for point in coords: distance = ((point[0] - center[0]) ** 2 + (point[1] - center[1]) ** 2 + (point[2] - center[2]) ** 2) ** 0.5 ### direkte Entfernung zwischen zwei Punkten (point(X) zu center(X); ...) if distance > hole_radius: ### wenn distance groesser als radius dann point coords_with_hole.append(point) rs.DeleteObjects(rs.AllObjects()) ### entfernt alle Punkte rs.AddPoints(coords_with_hole) ### fuegt die neuen Punkte der liste hinzu #dm.textDots(coords_with_hole) #dm.PointRadius(displayModeX=0, rad=3, styl=1) #rs.ZoomExtents() #rs.DeleteObjects(rs.AllObjects()) ##############################start-copy-of-ChatGPT############################# ###Rot-Gruen Farbverlauf entlang der x-, y-Achse, z-Achse fester Blauanteil #max_x = max([point[0] for point in coords_with_hole]) #max_y = max([point[1] for point in coords_with_hole]) #max_z = max([point[2] for point in coords_with_hole]) # #for point in coords_with_hole: # ## Normalisiere die Koordinaten in einen Bereich von 0 bis 255 # red_value = int((point[0] / max_x) * 255) if max_x != 0 else 0 # Farbverlauf entlang der x-Achse (Rot) # green_value = int((point[1] / max_y) * 255) if max_y != 0 else 0 # Farbverlauf entlang der y-Achse (Gruen) # blue_value = 150 # Konstanter Blauwert entlang der z-Achse # # ## Setze die Farbe als Kombination von R, G und festem Blauwert # color = [red_value, green_value, blue_value] # # ## Fuege den Punkt hinzu und setze die Farbe # obj = rs.AddPoint(point) # rs.ObjectColor(obj, color) ##############################end-copy-of-ChatGPT############################### dm.PointRadius(displayModeX=0, rad=3, styl=1) print len(coords_with_hole), "Punkte generiert" rs.ZoomExtents()