Help with translating this python script for Differential Growth

Hi all,

In this post David Bachman figured out how to achieve differential growth without scripting by looping Kangaroo trough Anemone.

He only uses a couple lines of python “to split line segments that get too long. That could have been done with only Grasshopper components, but doing it in Python was just too easy.”

I don’t speak any Python - nor any other code - and I can’t figure out what this code does exactly. Would anybody be so kind as to “translate” it to the respective grasshopper components?

This is the script - it’s also in the attached .gh file

import rhinoscriptsyntax as rs

increment = 0.01
splitLength = 2.0

l=

for i in range(len(Lines)):
L=Lines[i]
if rs.CurveLength(L)> splitLength:
l.append(rs.AddLine(rs.CurveStartPoint(L),rs.CurveMidPoint(L)))
l.append(rs.AddLine(rs.CurveMidPoint(L),rs.CurveEndPoint(L)))
else:
l.append(L)

DifferentialGrowth.gh (14.6 KB)

Hello,

I don’t know any GrassHopper but the script is taking a list of curves and splitting any curves which are longer than 2 in half. The increment is not used.

It outputs a new list in the same order as the input list

Pretty cool script.
This purple group has the same output as the Python but isn’t elegant or fast…


DifferentialGrowths_2019Nov23a.gh (24.6 KB)

To see the Python at full speed, the purple group must be disabled.
Can’t be sure the output is identical because the pattern looks different each time it’s run?

P.S. This version (below) feels faster, approximately 1.5X the Python time?


DifferentialGrowths_2019Nov23b.gh (25.8 KB)

P.P.S. Version 3 (below) - faster yet?


DifferentialGrowths_2019Nov23c.gh (24.5 KB)

Thanks a lot Joseph!