/*
squareFibonacci.mel v1.0
Author: Nate Lang
web: natelang3d.com
Install: Copy this file into a mel shelf button
Use:
Creates a fibonacci spiral that has right angles.
PATTERN:
0 1 1 2 3 5 8 13 21
prevNum + currentNum = nextNum
GRID PATTERN:
Starting:
(0,0)
++ 1 (1,1)
+- 1 (2,0)
-- 2 (0,-2)
-+ 3 (-3,1)
++ 5 (2,6)
+- 8 (10,-2)
-- 13 (-3,-15)
-+ 21 (-24,6)
*/
//Use this to increase or decrease number of itterations
int $steps = 20;
//-----------------------------------------
//create curve with specified steps and put points at 0 0 0
string $curveName = ("fiboCurve");
string $baseCurveName = `curve -degree 1 -point 0 0 0 -point 0 5 0 -point 0 10 0`;
string $index = `match "[0-9]+$" $baseCurveName`;
rebuildCurve -degree 1 -ch off -replaceOriginal false -spans ($steps - 1) -name ($curveName + $index);
string $shapeName[] = `listRelatives -children ($curveName + $index)`;
print ("ShapeName:" + $shapeName[0] + "\n");
for ($i=0; $i<$steps; $i++)
{
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].yValue") 0;
}
delete $baseCurveName;
//-----------------------------------------
int $prevNum = 0;
int $currentNum = 1;
int $nextNum = 1;
int $typeMov = 1;
int $locX = 0;
int $locZ = 0;
for ($i=1; $i<=$steps; $i++)
{
if ($typeMov == 1)
{
//print ("type1\n");
$locX = $locX + $currentNum;
$locZ = $locZ + $currentNum;
print ("coordX:"+$locX+"\n");
print ("coordZ:"+$locZ+"\n");
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].xValue") $locX;
//setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].yValue") 0;
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].zValue") $locZ;
$typeMov++;
}
else if ($typeMov == 2)
{
//print ("type2\n");
$locX = $locX + $currentNum;
$locZ = $locZ - $currentNum;
print ("coordX:"+$locX+"\n");
print ("coordZ:"+$locZ+"\n");
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].xValue") $locX;
//setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].yValue") 0;
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].zValue") $locZ;
$typeMov++;
}
else if ($typeMov == 3)
{
//print ("type3\n");
$locX = $locX - $currentNum;
$locZ = $locZ - $currentNum;
print ("coordX:"+$locX+"\n");
print ("coordZ:"+$locZ+"\n");
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].xValue") $locX;
//setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].yValue") 0;
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].zValue") $locZ;
$typeMov++;
}
else if ($typeMov == 4)
{
//print ("type4\n");
$locX = $locX - $currentNum;
$locZ = $locZ + $currentNum;
print ("coordX:"+$locX+"\n");
print ("coordZ:"+$locZ+"\n");
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].xValue") $locX;
//setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].yValue") 0;
setAttr ("fiboCurve" + $index + "Shape" + ".controlPoints[" + $i + "].zValue") $locZ;
$typeMov = 1;
}
print ($currentNum + "\n");
$prevNum = $currentNum;
$currentNum = $nextNum;
$nextNum = $currentNum + $prevNum;
}