aa_turtle_setModelCommand

 




Back to ->Week 9 - User Interface

Adding Complexity - the aa_turtle_setModelCommand




There is a new turtle command that is very powerful. It allows you to specify to the turtle a procedure that you write that takes one argument - length.




Lets create such a function first. This will be a simple parametric model that takes only $length:






global proc string facade( float $len ) {

$facadeParts = `group -em`;

$dimBay = 2;
// create a facade from 0 to $len
$reps = $len/$dimBay;

$i = 0; $shiftx=0;
while ($i <= $reps)
{
$cube = `polyCube`;
move $shiftx 2.5 0;
scale .5 5 .5;
$shiftx += $dimBay;
parent $cube $facadeParts;
$i++;
}

$cube = `polyCube`;
scale $len 2 .25;
move ($len/2) 1 0;
parent $cube $facadeParts;

$cube = `polyCube`;
scale $len 2 .25;
move ($len/2) 5 0;
parent $cube $facadeParts;

select $facadeParts;

return $facadeParts;
}










Now we just have to add the model to the makeCurve Routine:



global proc string makeCurve(float $startLen, float $angle, float $generations, float $generationScale) {

$len = $startLen;

$t = aa_turtle_newturtle("LINE");

// --- USE THE NEW TURTLE COMMAND
aa_turtle_setModelCommand($t, "facade");

aa_turtle_setPosition($t, <<0,0,0>>);

$i = 0;
while ($i < $generations) {

aa_turtle_move($t, $len);
aa_turtle_turn($t, $angle, 0);

$len *= $generationScale;
$i++;
}

$curve = aa_turtle_getCurve($t);

// ---- ANOTHER NEW TURTLE COMMAND
$model = aa_turtle_getModel($t);

parent $model $curve;

aa_turtle_done($t);

select $curve;
return $curve;

}


  • aa_turtle_setModelCommand