def cylinder_vertices(Subd, Vertices, Height, RadiusBot, RadiusTop, Separate): theta = 360 / Vertices heightSubd = Height / (Subd + 1) X = [] Y = [] Z = [] for i in range(Subd + 2): radius = RadiusBot - ((RadiusBot - RadiusTop) / (Subd + 1)) * i for j in range(Vertices): X.append(radius * cos(radians(theta * j))) Y.append(radius * sin(radians(theta * j))) Z.append(heightSubd * i) points = list(sv_zip(X, Y, Z)) if Separate: out = [] out_ = [] x = 0 for y, P in enumerate(points): x += 1 out_.append(P) if x // Vertices: out.append(out_) out_ = [] x = 0 points = out # points = list(zip(*out)) return points
def cylinder_vertices(Subd, Vertices, Height, RadiusBot, RadiusTop, Separate): theta = 360 / Vertices heightSubd = Height / (Subd + 1) X = [] Y = [] Z = [] for i in range(Subd + 2): radius = RadiusBot - ((RadiusBot - RadiusTop) / (Subd + 1)) * i for j in range(Vertices): X.append(radius * cos(radians(theta * j))) Y.append(radius * sin(radians(theta * j))) Z.append(heightSubd * i) points = list(sv_zip(X, Y, Z)) if Separate: out = [] out_ = [] x = 0 for y, P in enumerate(points): x += 1 out_.append(P) if x // Vertices: out.append(out_) out_ = [] x = 0 points = out #points = list(zip(*out)) return points
def sv_main(data=[],step=0.3): # in boilerplate - make your own sockets in_sockets = [ ['v', 'vertices', data], ['s', 'Step (0...3)', step], ] # import libreryes - your defined from data_structure import sv_zip from math import sin, cos #from random import random # your's code here step_ = (step%6-3)/1.2 #ran = random() if data: out_x_ = [sin(i[0]/step_) for i in data] out_y_ = [cos(i[0]/step_) for i in data] out_z = [sin(i[0]*step_) for i in data] out_x = [i+sin(out_x_[k]) for k, i in enumerate(out_x_)] out_y = [i+cos(out_y_[k]) for k, i in enumerate(out_y_)] out = list(sv_zip(out_x,out_y,out_z)) edg=[[i,i-1] for i, ed in enumerate(out_x) if i>0] else: out_x = [i*step_ for i in range(100)] out_y = [cos(i*step_) for i in out_x] out_z = [sin(i*step_)*out_y[k] for k, i in enumerate(out_y)] out = list(sv_zip(out_x,out_y,out_z)) edg=[[i,i-1] for i, ed in enumerate(out_x) if i>0] # out boilerplate - set your own sockets packet out_sockets = [ ['v', 'ver', [out]], ['s', 'edg', [edg]], ] return in_sockets, out_sockets
def update(self): # inputs if 'Nº Vertices X' in self.inputs and self.inputs['Nº Vertices X'].links: IntegerX = int(SvGetSocketAnyType(self, self.inputs['Nº Vertices X'])[0][0]) else: IntegerX = self.int_X if 'Nº Vertices Y' in self.inputs and self.inputs['Nº Vertices Y'].links: IntegerY = int(SvGetSocketAnyType(self, self.inputs['Nº Vertices Y'])[0][0]) else: IntegerY = self.int_Y if 'Step X' in self.inputs and self.inputs['Step X'].links: StepX = SvGetSocketAnyType(self, self.inputs['Step X'])[0] listVertX = [] fullList(StepX, IntegerX) for i in range(IntegerY): listVertX.append(0.0) for j in range(IntegerX-1): listVertX.append(listVertX[j]+StepX[j]) else: StepX = self.step_X listVertX = [] for i in range(IntegerY): for j in range(IntegerX): listVertX.append(0.0+j) listVertX = [StepX*i for i in listVertX] if 'Step Y' in self.inputs and self.inputs['Step Y'].links: StepY = SvGetSocketAnyType(self, self.inputs['Step Y'])[0] listVertY = [] fullList(StepY, IntegerY) for i in range(IntegerX): listVertY.append(0.0) for i in range(IntegerY-1): for j in range(IntegerX): listVertY.append(listVertY[IntegerX*i]+StepY[i]) else: StepY = self.step_Y listVertY = [] for i in range(IntegerY): for j in range(IntegerX): listVertY.append(0.0+i) listVertY = [StepY*i for i in listVertY] # outputs if 'Vertices' in self.outputs and self.outputs['Vertices'].links: X = listVertX Y = listVertY Z = [0.0] max_num = max(len(X), len(Y), len(Z)) fullList(X, max_num) fullList(Y, max_num) fullList(Z, max_num) points = list(sv_zip(X, Y, Z)) if self.Separate: out = [] for y in range(IntegerY): out_ = [] for x in range(IntegerX): out_.append(points[IntegerX*y+x]) out.append(out_) SvSetSocketAnyType(self, 'Vertices', [out]) else: SvSetSocketAnyType(self, 'Vertices', [points]) if 'Edges' in self.outputs and self.outputs['Edges'].links: listEdg = [] for i in range(IntegerY): for j in range(IntegerX-1): listEdg.append((IntegerX*i+j, IntegerX*i+j+1)) for i in range(IntegerX): for j in range(IntegerY-1): listEdg.append((IntegerX*j+i, IntegerX*j+i+IntegerX)) edg = list(listEdg) SvSetSocketAnyType(self, 'Edges', [edg]) if 'Polygons' in self.outputs and self.outputs['Polygons'].links: listPlg = [] for i in range(IntegerX-1): for j in range(IntegerY-1): listPlg.append((IntegerX*j+i, IntegerX*j+i+1, IntegerX*j+i+IntegerX+1, IntegerX*j+i+IntegerX)) plg = list(listPlg) SvSetSocketAnyType(self, 'Polygons', [plg])