Open up the "aa_lsystem.mel" script and look for the section in the aa_lsystem_draw procedure that loooks like below:
if($nextchar == $thisrule_operand){
if($tmp[0] == "turn"){
aa_turtle_turn($turtle,$tmp[1],$tmp[2]);
}else{
aa_turtle_move($turtle,$tmp[1]);
}
}
This is the only part of the entire l-system script that has a 'move' command for the turtle, so this is where the actual drawing of the l-system happens. If you want to augment the code by adding additional operations to the 'draw' you can add it here. For example, replace the aa_turtle_move with the code below, this should look familiar to you, it positions a cube.
aa_turtle_move($turtle,$tmp[1]);
$pos = aa_turtle_getPosition($turtle);
polyCube;
move $pos[0] $angle[0] $pos[2];
Re-load the l-system script in maya and run one of the examples, such as a 'Quadratic Koch Island'.
$tmp = "a+a+a+a";
$rules[0] = "a->a+a-a-aa+a+a-a";
$drawrules[0] = "a->move 1";
$drawrules[1] = "+->turn 90 0";
$drawrules[2] = "-->turn -90 0";
$tmp = aa_lsystem_replace($tmp,$rules,2);
aa_lsystem_draw($tmp,$drawrules,<<0,0,0>>,0,0);
Along with the position information of the turtle, you can also use the azimuth and alititude (direction) information. For example, adding this code (after the previous code you just added) scales the objects based on their direction.
$angle = aa_turtle_getDirection($turtle);
scale (($angle[0]/90) * 10) (($angle[0]/90)* 10) (($angle[0]/90)* 10);
Try this with a simple tree:
$tmp = "a";
$rules[0] = "a->a[-a]a[+a][a]";
$drawrules[0] = "a->move 1";
$drawrules[1] = "+->turn 30 0";
$drawrules[2] = "-->turn -30 0";
$tmp = aa_lsystem_replace($tmp,$rules,3);
aa_lsystem_draw($tmp,$drawrules,<<0,0,0>>,90,0);]
Instead of using basic primitives from maya, you can make your own as you have in previous work session. The code below is from class_04 and makes a new parametric 'primitive' called 'house'.
global proc string floor ( float $width, float $depth, float $height, float $ledge ) {
// return group
$floorItems = `group -em`;
// floor deck
$floordeck = `nurbsCube -p 0 .5 0`;
// init vars
$width += $ledge;
$depth += $ledge;
$thickness = 1;
// Transfroms
move 0 .5 0;
scale $width $thickness $depth;
parent $floordeck [0] $floorItems;
return $floorItems;
}
global proc string house ( float $width, float $depth, float $height ) {
// return group
$houseItems = `group -em`;
// 1. Create
$glazing = `nurbsCube -p 0 .5 0`;
// 2. Transformation
select $glazing;
move 0 .5 0;
scale $width $height $depth;
// 3. Parent
parent $glazing[0] $houseItems;
// floors
// 0. Initialize
$floorHeight = 10.0;
$numFloors = $height / $floorHeight;
$ledge = 2;
$i = 0;
$currentHeight = 0;
while ($i++ < $numFloors ) {
// 1. Create
$floor = floor( $width, $depth, $floorHeight, $ledge);
// 2. Transformation
select $floor;
move 0 $currentHeight 0;
// 3. Parent
parent $floor $houseItems;
$currentHeight += $floorHeight;
}
// Roof
// 0. Initialize
$ledge *= 3;
// 1. Create
$floor = floor( $width, $depth, 1, $ledge);
// 2. Transform
select $floor;
move 0 $currentHeight 0;
// 3. Parent
parent $floor $houseItems;
select $houseItems;
return $houseItems;
}
You can use the 'house' inside the l-system instead of a cube. Replace the code from before with:
aa_turtle_move($turtle,$tmp[1]);
$pos = aa_turtle_getPosition($turtle);
$angle = aa_turtle_getDirection($turtle);
$house = house((($angle[0]/90 * 5)),(($angle[0]/90 * 5)),($angle[0] * 20));
move $pos[0] $angle[0] $pos[2] $house;
This code uses the position and direction to produce different scale buildings. You can use the 'Quadratic Koch Island' again, or the tree example:
$tmp = "a+a+a+a";
$rules[0] = "a->a+a-a-aa+a+a-a";
$drawrules[0] = "a->move 1";
$drawrules[1] = "+->turn 90 0";
$drawrules[2] = "-->turn -90 0";
$tmp = aa_lsystem_replace($tmp,$rules,1);
aa_lsystem_draw($tmp,$drawrules,<<0,0,0>>,0,0);
Try different relationships between position/direction and the house size.
aa_turtle_move($turtle,$tmp[1]);
$pos = aa_turtle_getPosition($turtle);
$angle = aa_turtle_getDirection($turtle);
$house = house((($angle[0] * 5)),(($angle[0] * 5)),($angle[0] * 20));
move $pos[0] $angle[0] $pos[2] $house;
Also, try using a 'bigger' l-system by changing the 'move' distances.
$tmp = "a+a+a+a";
$rules[0] = "a->a+a-a-aa+a+a-a";
$drawrules[0] = "a->move 100";
$drawrules[1] = "+->turn 90 0";
$drawrules[2] = "-->turn -90 0";
$tmp = aa_lsystem_replace($tmp,$rules,1);
aa_lsystem_draw($tmp,$drawrules,<<0,0,0>>,0,0);
aa_turtle_move($turtle,$tmp[1]);
$pos = aa_turtle_getPosition($turtle);
$angle = aa_turtle_getDirection($turtle);
$house = house((($angle[0] * 15)),(($angle[0] * 15)),($angle[0] * 20));
move $pos[0] ($angle[0] * 10) $pos[2] $house;
$tmp = "a";
$rules[0] = "a->a[-a]a[+a][a]";
$drawrules[0] = "a->move 100";
$drawrules[1] = "+->turn 30 0";
$drawrules[2] = "-->turn -30 0";
$tmp = aa_lsystem_replace($tmp,$rules,3);
aa_lsystem_draw($tmp,$drawrules,<<0,0,0>>,90,0);