Fibbonacci and Factorial

Recursive functions in Design Script

Pisano Period

Patterns
Colors 1
Colors 2
Colors 3
Colors 4
Colors 5
Patterns
Random colors based on Pisano Period
Colors 1
Colors 2
Colors 3
Colors 4
Colors 5
Pisano Period
wc = 20;
hc = 12;
wd = 2;
ht = 2;
//Pisano Period
fp1 = fibbonacci(1..wc)%(1..hc)<1>;
//Random Colors
uq1 = List.UniqueItems(List.Flatten(fp1,-1));
rn1 = Math.Round(Math.RemapRange(Math.RandomList(List.Count(uq1)),0,255));
cl1 = Color.ByARGB(255,rn1,List.Shuffle(rn1),List.Reverse(rn1));
cl2 = Dictionary.ByKeysValues(uq1+"",cl1).ValueAtKey(fp1+"");
//Panels
pn1 = Rectangle.ByWidthLength(Plane.ByOriginNormal(Point.ByCoordinates((wd/2..#wc..wd),0,(ht/2..#hc..ht)<2>),Vector.YAxis()),wd,ht).Patch();
pn2 = GeometryColor.ByGeometryColor(pn1,cl2);

Fibbonacci Series

Fibbonacci
def fibbonacci(n)
{
return [Imperative]
{
if (n == 0)
{
return 0;
}
elseif (n == 1)
{
return 1;
}
else
{
return (fibbonacci(n-1) + fibbonacci(n-2));
}
}
};

Factorials

Factorial
def factorial(n)
{
return [Imperative]
{
if (n <= 1)
{
return 1;
}
else
{
return n * factorial(n-1);
}
}
};