import rhinoscriptsyntax as rs import math #clear everything and start from scratch rs.DeleteObjects(rs.AllObjects()) #parameters tower_height = 400 num_segments = 100 base_radius = 10 cosine_amplitude = 8 cosine_frequency = 6 #reduction top and base reduction_height = 30 reduction_factor = 0.7 #function to create radii def modulated_radius(z, amplitude, frequency, base_radius): #cosine wave radius = base_radius + amplitude * math.cos(2 * math.pi * frequency * z / tower_height) #top reduction if z > (tower_height - reduction_height): reduction = (z - (tower_height - reduction_height)) / reduction_height radius *= (1 - reduction * reduction_factor) #base reduction elif z < reduction_height: reduction = (reduction_height - z) / reduction_height radius *= (1 - reduction * reduction_factor) return radius #base curves curves = [] for i in range(num_segments + 1): #calculate height step z = i * (tower_height / num_segments) #calculate radius radius = modulated_radius(z, cosine_amplitude, cosine_frequency, base_radius) #create a circle circle = rs.AddCircle((0, 0, z), radius) curves.append(circle) #loft loft = rs.AddLoftSrf(curves, loft_type=0) if loft: loft = loft[0] rs.CapPlanarHoles(loft) rs.DeleteObjects(curves) rs.EnableRedraw(True)