Fractal Curves with Rhino Python

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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"
«
»