Stuck in Grasshopper-Python Recursion

There was another conversation floating around about this…I forget where. There were a few different flavors of suggestions. Here is a ghpython example, based on those conversations:( I made that component for fun from pieces of the code suggested…the code is below to make your own).

"""RecursionThing: A classic recursion thing. 
    Inputs:
        C: (Curve) Boundary Curves
        L: (int) Number of internal offsets, (loops)
        t: (float) Interior curve parameter for offset
        D: (float) If making 3D offset distance in Z relative to World XY
        B: (bool) Boolean, Make 3D
    Output:
        IC: Interior Curves"""

import Rhino
import Grasshopper
import sys

def SpiroGraph2():
    current_crv = C
    results = []
    
    for i in xrange(L+1):
        segments = current_crv.DuplicateSegments()
        if len(segments) < 2: return
        mid_points = []
        for segment in segments:
            mid_pt = segment.PointAtNormalizedLength(t)
            if B == True:
                newmid_pt = Rhino.Geometry.Point3d(mid_pt[0], mid_pt[1], mid_pt[2]+D)
                mid_points.append(newmid_pt)
            else:
                mid_points.append(mid_pt)
        mid_points.append(mid_points[0])
        new_crv = Rhino.Geometry.Polyline(mid_points)
        results.append(new_crv)
        current_crv = new_crv.ToNurbsCurve()
    return results

try:
    IC = SpiroGraph2()
except:
    ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning,str(sys.exc_info()[1]))

(pretty sure this was the convo)

3 Likes