I have a program in Python that I'm trying to convert into PHP (as allowed by the program's licence) that draws random polygons. Part of this code contains a recursive function that splits the first polygon sent to it into two new polygons (polygon B and polygon A) then these polygons get split again by way of the recursive function, up to a pre-determined number of iterations (using the value in $depth, which is tested for inside the function but omitted from my code):
<?php
function generate_polygons($polygon, $depth, $polygon_type=NULL)
{
// code omitted for clarity
$this->generate_polygons($polygon_b, $depth-1, 'B');
$this->generate_polygons($polygon_a, $depth-1, 'A');
}
$generate_polygons($starting_polygon, $depth);
?>
What I want to understand is how to visualize two levels of recursion to determine at what stage each polygon is split?
With input from @ADyson and @IMSoP I have been able to produce a simple animation showing the exact sequencing of the recursion:
As already mentioned, PHP does not do anything different to other programming languages in this respect (each recursion is completed fully before moving on to the next recursion) but, for me, the actual sequencing is a lot easier to understand now that I can fully visualize the process.
Thank you again for everyone's help.