Increasingly complex lines

Here is a more good script using C# and some methods. You just have to poulate whatever you want with lines. The length (L) control the total length (Loutput = L * (number of segments +1)) of the ouput curve
You can define for each point a maximum angle of deviation (in radians), you can also define the number of segments for each curve.
It is surely better to make the preview with curve and then adding meshes and colors …

 private void RunScript(List<Line> lst_lines, List<double> lst_factors, List<int> lst_segmentsNumber, int seed, ref object A)
  {
    //Random growth of lines
    if (lst_lines == null || lst_lines.Count <= 0) return;
    if (lst_factors == null || lst_factors.Count <= 0) return;
    if (lst_segmentsNumber == null || lst_segmentsNumber.Count <= 0) return;
    //Fill the list if not enough parameters
    if (lst_factors.Count < lst_lines.Count)
    {
      int n = lst_factors.Count;
      for (int i = n ; i < lst_lines.Count; i++)
      {
        lst_factors.Add(lst_factors[n - 1]);
      }
    }
    //Fill the list if not enough parameters
    if (lst_segmentsNumber.Count < lst_lines.Count)
    {
      int m = lst_segmentsNumber.Count;
      for (int i = m ; i < lst_lines.Count; i++)
      {
        lst_segmentsNumber.Add(lst_segmentsNumber[m - 1]);
      }
    }
    //Output DataTree of lines
    DataTree<Line> dt_linesCurved = new  DataTree<Line>();
    Random rnd = new Random(seed);
    for (int i = 0; i < lst_lines.Count; i++)
    {
      List<Line> lst_linesCurved = RandomGrowthLine(lst_lines[i], lst_factors[i], lst_segmentsNumber[i], rnd);
      dt_linesCurved.AddRange(lst_linesCurved, new GH_Path(i));
    }
    A = dt_linesCurved;
  }

  // <Custom additional code> 

  /// <summary>
  /// Growth randomly a line adding lines rotated randomly to the end of the line
  ///Each added line will have the same length
  ///Laurent Delrieu 07/02/2020
  /// </summary>
  /// <param name="arg_line">Initial line</param>
  /// <param name="arg_factor">Max angle (radians) of rotation</param>
  /// <param name="arg_segmentsNumber">Number of segments added</param>
  /// <param name="arg_rnd">Random function</param>
  /// <returns>List of line touching each other</returns>
  public List<Line> RandomGrowthLine(Line arg_line, double arg_factor, int arg_segmentsNumber, Random arg_rnd)
  {
    List<Line> lines_out = new List<Line>();

    lines_out.Add(arg_line);

    for (int i = 0; i < arg_segmentsNumber ; i++)
    {
      Line new_line = GetRandomLine(lines_out[lines_out.Count - 1], arg_factor, arg_rnd);
      lines_out.Add(new_line);
    }
    return lines_out;
  }
  /// <summary>
  /// Growth randomly a line adding a line rotated randomly to the end of the line
  /// Returned line as the same line as previous
  ///Laurent Delrieu 07/02/2020
  /// <summary>
  /// <param name="arg_line">Initial Line</param>
  /// <param name="arg_factor">Max angle (radians) of rotation</param>
  /// <param name="arg_rnd">Random function</param>
  /// <returns>New Line</returns>
  public Line GetRandomLine(Line arg_line, double arg_factor, Random arg_rnd)
  {
    Line line = new Line(arg_line.From, arg_line.To);
    line.Transform(Transform.Translation(line.Direction));

    Vector3d direction = arg_line.Direction;
    Vector3d perpandicular = Vector3d.CrossProduct(Vector3d.XAxis, direction);
    if (perpandicular.Length < 1e-12)
    {
      perpandicular = Vector3d.CrossProduct(Vector3d.YAxis, direction);
    }
    double angle = arg_rnd.NextDouble() * arg_factor;
    line.Transform(Transform.Rotation(angle, perpandicular, line.From));


    double rollAngle = arg_rnd.NextDouble() * Math.PI * 2;
    line.Transform(Transform.Rotation(rollAngle, arg_line.Direction, line.From));

    return line;
  }


randow_growth_line_LEGACY.gh (25.0 KB)

19 Likes