Fibbonacci and Factorial
Recursive functions in Design Script

Pisano Period

Patterns
Colors 1
Colors 2
Colors 3
Colors 4
Colors 5
Random colors based on Pisano Period
Pisano Period
1
wc = 20;
2
hc = 12;
3
wd = 2;
4
ht = 2;
5
6
//Pisano Period
7
fp1 = fibbonacci(1..wc)%(1..hc)<1>;
8
9
//Random Colors
10
uq1 = List.UniqueItems(List.Flatten(fp1,-1));
11
rn1 = Math.Round(Math.RemapRange(Math.RandomList(List.Count(uq1)),0,255));
12
cl1 = Color.ByARGB(255,rn1,List.Shuffle(rn1),List.Reverse(rn1));
13
cl2 = Dictionary.ByKeysValues(uq1+"",cl1).ValueAtKey(fp1+"");
14
15
//Panels
16
pn1 = Rectangle.ByWidthLength(Plane.ByOriginNormal(Point.ByCoordinates((wd/2..#wc..wd),0,(ht/2..#hc..ht)<2>),Vector.YAxis()),wd,ht).Patch();
17
pn2 = GeometryColor.ByGeometryColor(pn1,cl2);
Copied!
pisanoPeriod.zip
2KB
Binary
Dynamo Version 2.11

Fibbonacci Series

Fibbonacci
1
def fibbonacci(n)
2
{
3
return [Imperative]
4
{
5
if (n == 0)
6
{
7
return 0;
8
}
9
elseif (n == 1)
10
{
11
return 1;
12
}
13
else
14
{
15
return (fibbonacci(n-1) + fibbonacci(n-2));
16
}
17
}
18
};
Copied!

Factorials

Factorial
1
def factorial(n)
2
{
3
return [Imperative]
4
{
5
if (n <= 1)
6
{
7
return 1;
8
}
9
else
10
{
11
return n * factorial(n-1);
12
}
13
}
14
};
Copied!
Last modified 9mo ago