Fibbonacci and Factorial

Recursive functions in Design Script

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

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

Factorials

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

Last updated