Fractal Curves with Rhino Python

by Tuğrul Yazar | July 31, 2017 15:14

A simple Rhino Python script that generates fractal curves. An example is a test with the Gosper-Peano curve. However the script is not supporting segment directions, which is why the result is not the intended curve. Curve directions could be implemented in the future.

# Drawing Simple Fractal Curves
# 31.07.2017 www.designcoding.net - Tugrul Yazar
import rhinoscriptsyntax as rs
import copy
initials = rs.GetObject("Select Initial Shape",4)
referenceA = rs.GetPoint("Place Reference Point A")
referenceB = rs.GetPoint("Place Reference Point B")
iteration = rs.GetInteger("Enter Number of Iterations",3,1,10)
if initials and referenceA and referenceB and iteration:
      if rs.CurveDegree(initials) > 1:
            rs.RebuildCurve(initials,1)
      shape = []
      shape.append(initials)
      for i in range(iteration):
            segments = rs.ExplodeCurves(shape)
            rs.HideObjects(shape)
            new = []
            for segment in segments:
                  starts = rs.CurveStartPoint(segment)
                  ends = rs.CurveEndPoint(segment)
                  newsegment = rs.OrientObject(initials,[referenceA,referenceB],[starts,ends],3)
                  new.append(newsegment)
            shape = copy.deepcopy(new)
            rs.HideObjects(segments)
      rs.ShowObjects(shape)
else:
      print "Nothing done. One or more inputs were not defined"

Source URL: https://www.designcoding.net/fractal-curves-with-rhino-python/