global proc rkoLissajousCurve ()

/*
These are the equations for the Lissajous Curve for the x, y, and z axies.

x = A*cos((OmegaX + time) - deltaX);
y = B*cos((OmegaY + time) - deltaY);
z = C*cos((OmegaZ + time) - deltaZ);

The following are all of the floating point variables that are being used in the expression editor.

float $A = 10.0;
float $B = 10.0;
float $C = 10.0;

float $OmegaX = 1.0;
float $OmegaY = 3.0;
float $OmegaZ = 4.0;

float $PI = 3.1415926535879;

float $deltaX = $PI *0.5;
float $deltaY = $deltaX;
float $deltaZ = $deltaX;

//float $pid = particleId + 1.0;

//float $y = sin(time + particleId);

float $x = $A * cos (($OmegaX * (time + particleId)) - $deltaX);
float $y = $B * cos (($OmegaY * (time + particleId)) - $deltaY);
float $z = $C * cos (($OmegaZ * (time + particleId)) - $deltaZ);

position = << $x, $y, $z >>;

//This is what the expression editior translates out in the script editor

dynExpression -s ("float $A = curve1Particle.A;\n" +
"float $B = curve1Particle.B;\n" +
"float $C = curve1Particle.C;\n\n" +
"float $OmegaX = curve1Particle.OmegaX;\n" +
"float $OmegaY = curve1Particle.OmegaY;\n" +
"float $OmegaZ = curve1Particle.OmegaZ;\n\n" +
"float $PI = 3.1415926535879;\n\n" +
"float $deltaX = $PI *0.5;\n" +
"float $deltaY = $deltaX;\n" +
"float $deltaZ = $deltaX;\n\n" +
"//float $pid = particleId + 1.0;\n\n" +
"//float $y = sin(time + particleId);\n\n" +
"float $x = $A * cos (($OmegaX * (time + particleId)) - $deltaX);\n" +
"float $y = $B * cos (($OmegaY * (time + particleId)) - $deltaY);\n" +
"float $z = $C * cos (($OmegaZ * (time + particleId)) - $deltaZ);\n\n" +
"position = << $x, $y, $z >>;") -rbd curve1ParticleShape;

 

*/

{
string $curveCommand = "curve -degree 3 " ;
int $curveCVs = 250 ;
int $i ;
for ($i = 0; $i < $curveCVs; $i++)
$curveCommand += ("-point " + $i + " 0 0 ") ;

$curveCommand += ";" ;

string $rkoLissajousCurve = eval($curveCommand) ;

// This allows you to convert the curve to softbodies so that you can use the particle system.

string $results[] = `soft -convert $rkoLissajousCurve` ;
$results = `listRelatives -shapes $results[0]` ;
string $softbodyParticleShape = $results[0] ;

//You want to make sure that you add the attributes before you even make the expression
//that way the attributes can access the expression.

addAttr -ln "OmegaX" -at double -min 1.0 -max 20.0 -dv 10.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".OmegaX");

addAttr -ln "OmegaY" -at double -min 1.0 -max 20.0 -dv 10.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".OmegaY");

addAttr -ln "OmegaZ" -at double -min 1.0 -max 20.0 -dv 10.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".OmegaZ");

addAttr -ln "A" -at double -min -15.0 -max 15.0 -dv 1.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".A");

addAttr -ln "B" -at double -min -15.0 -max 15.0 -dv 3.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".B");

addAttr -ln "C" -at double -min -15.0 -max 15.0 -dv 4.0 $rkoLissajousCurve;
setAttr -e -keyable true ($rkoLissajousCurve + ".C");

string $dynamicExpression =
"float $A = " + $rkoLissajousCurve + ".A;\n" +
"float $B = " + $rkoLissajousCurve + ".B;\n" +
"float $C = " + $rkoLissajousCurve + ".C;\n\n" +
"float $OmegaX = " + $rkoLissajousCurve + ".OmegaX;\n" +
"float $OmegaY = " + $rkoLissajousCurve + ".OmegaY;\n" +
"float $OmegaZ = " + $rkoLissajousCurve + ".OmegaZ;\n\n" +
"float $PI = 3.1415926535879;\n\n" +
"float $deltaX = $PI *0.5;\n" +
"float $deltaY = $deltaX;\n" +
"float $deltaZ = $deltaX;\n\n" +
"//float $pid = particleId + 1.0;\n\n" +
"//float $y = sin(time + particleId);\n\n" +
"float $x = $A * cos (($OmegaX * (time + particleId)) - $deltaX);\n" +
"float $y = $B * cos (($OmegaY * (time + particleId)) - $deltaY);\n" +
"float $z = $C * cos (($OmegaZ * (time + particleId)) - $deltaZ);\n\n" +
"position = << $x, $y, $z >>;" ;

dynExpression -runtimeAfterDynamics -string $dynamicExpression $softbodyParticleShape ;
dynExpression -creation -string $dynamicExpression $softbodyParticleShape ;

}