Video thumbnail
Row Your Boat (Part 3)
In this video we animate a 2D drawing. We add a layer of complexity to our animation process by iterating through lines and line types and by drawing each line (rather than dropping it in fully formed) as it arrives in our queue.

Back to Animations
Code
Below is the C# script we used to make the Row Your Boat component. This is all of the code from our scripting component.
    
// Grasshopper Script Instance
#region Usings
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
#endregion

public class Script_Instance : GH_ScriptInstance
{

    private void RunScript(
	bool reset,
	int counters,
	double speed,
	double waitFor,
	ref object a,
	ref object b)
    {
        if (reset){
            counterList.Clear();
            file_number = 0;
            justReset = true;
        }
        else{
            file_number++;

            if (counterList.Count < counters){
                // Initializing all counters to 0
                while (counterList.Count < counters){
                    counterList.Add(0.0);
                }
            }
            if (justReset){
                justReset = false;
            }
            else{
                for (int i = 0; i < counterList.Count; i++){
                    if (i==0 || counterList[i-1] >= waitFor){
                        if (counterList[i] < 1){
                            counterList[i] += speed;
                            if (counterList[i] > 1){
                                counterList[i] = 1;
                            }
                        }
                    }
                }
            }

        }

        a = counterList;
        b = file_number;
    }

    private List<double> counterList = new List<double>();
    private int file_number = 0;
    private bool justReset = false; // Flag that indicates if the script was just reset
}
  
And, in this code block is just the code for the small replace closed curve branches (inside the ClosePolys cluster).
    
// Grasshopper Script Instance
#region Usings
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
#endregion

public class Script_Instance : GH_ScriptInstance
{
  private void RunScript(
    DataTree<Point3d> tree,
    DataTree<Point3d> replace,
    ref object a)
      {
          DataTree<Point3d> newTree = new DataTree<Point3d>();

          for (int i = 0; i < tree.BranchCount; i++){
              var path = new GH_Path(i);
              var nextBranch = new List<Point3d>();

              if (replace.PathExists(path)){
                  nextBranch = replace.Branch(path);
              }
              else{
                  nextBranch = tree.Branch(path);
              }

              newTree.AddRange(nextBranch,path);
          }
          a = newTree;
      }
}