Video thumbnail
C# Quick Look Part 2
Recursive operations (in which a function's output becomes that function's input for the next step) are everywhere in natural systems and in computer programming. This video, and the previous video, touch on C# scripting in order to introduce these concepts.

If you are using Rhino 8, translating the code for the C# component might be a little tricky. An extra Grasshopper file (under "Downloads") is available below to help with this.

Back to Intro to Grasshopper Part 1
Code
Below is the code from the C# scripting component we used to adjust the positions of the points along the bottom curve.
    
// Grasshopper Script Instance
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{  
  private void RunScript(
	List<double> in_params,
	Curve in_curve,
	bool wrap,
	double weight,
	int iterations,
	ref object A,
	ref object B)
  {
    List<double> parameters = new List<double>();
    parameters = in_params.ToList();

    if (wrap) parameters.Add(1.0);

    List<Point3d> pts = new List<Point3d>();

    pts = FindPoints(parameters, in_curve);

    for (int i = 0; i < iterations; i++)
    {
      parameters = UpdateParameters(parameters, in_curve, weight);
    }

    pts = FindPoints(parameters, in_curve);


    A = pts;
    B = parameters;
  }

    public List<Point3d> FindPoints(List<double> p, Curve c)
  {
    List<Point3d> points = new List<Point3d>();
    foreach (double par in p)
    {
      Point3d new_p = new Point3d(c.PointAtNormalizedLength(par));
      points.Add(new_p);
    }

    return points;
  }

  public List<double> FindDistances(List<Point3d> p_list)
  {
    List<double> distances = new List<double>();
    for (int i = 1; i < p_list.Count; i++)
    {
      double newDistance = p_list[i].DistanceTo(p_list[i - 1]);
      distances.Add(newDistance);
    }

    return distances;
  }

  public List<double> UpdateParameters(List<double> pars, Curve in_c, double w)
  {
    List<double> new_pars = new List<double>();
    List<double> dists = new List<double>();
    List<double> norm_dists = new List<double>();
    List<Point3d> new_pts = new List<Point3d>();
    double crvLength = in_c.GetLength();

    new_pars = pars;
    new_pts = FindPoints(new_pars, in_c);
    dists = FindDistances(new_pts);
    foreach (double dis in dists)
    {
      double norm_dis = dis / crvLength;
      norm_dists.Add(norm_dis);
    }
    for (int i = 1; i < new_pars.Count - 1; i++)
    {
      double difference = norm_dists[i] - norm_dists[i - 1];
      new_pars[i] = new_pars[i] + (difference * w);
    }

    return new_pars;
  }
}
  
Resources
Fernandes, M. C., Aizenberg, J., Weaver, J. C., & Bertoldi, K. (2021). Mechanically robust lattices inspired by deep-sea glass sponges. Nature Materials, 20(2), 237–241. https://doi.org/10.1038/s41563-020-0798-1