Recursive 2D tree

  • Email
  • Sharebar
  • Email
Andy's picture

One of the powerful abilities of LOGO programming language is its recursive execution of procedure. Recursive call of procedure means a procedure calls itself until an exiting condition is met. A recursive procedure can be very simple yet it can produce complex and beautiful mathematical graphics such as fractal images and naturally occurring objects. 

There are quite a few classical recursive LOGO procedures available online. I have taken one from Joshua Bell's Logo Interpreter to show that the recursive procedures also work in VRMath2. Below is an example of a recursive tree.

As can be seen, the program defines a procedure called tree with an input as :size. The tree procedure calls itself (line: 6, 8 and 10) until the :size is less than 5 (line: 4) to exit the procedure. Because of the 3D virtual reality (VR) graphics of VRMath2, the following key differences from the traditional 2D LOGOs should be noted.

  1. The 2D LOGOs draw pixels on screen while VRMath2 creates objects internally in memory then render in 3D space. As a result, the performance of recursion in VRMath2 is not good at all. To draw a TREE 100 in 2D LOGOs is almost instant (less than a second). However, in VRMath2, it takes about 23 seconds (in my MacBook Pro 2011 model) to collect all 3D coordinates then render the tree object. 
  2. Because pixel is not applicable in the 3D VR space, the idea of distance is in fact the same as we have in real world. In VRMath2, the distance is measured as meter by default. In order to appropriately size the tree, I have to change the unit into centimeter (line: 15). And in order to draw a tree that goes up, I Roll Up the turtle (line: 18) before creating the tree.
  3. The JUMPBACK command in line 4 and 12 indicates the 3D object does not need to draw the lines already drawn in earlier FORWARD. This should increase the speed of creation a little bit. The "JUMP" series of command is associated with every moving command. They are useful when during PENDOWN and you wish to move the turtle without leaving a track.

Please leave me a comment below if you have any questions.

Files: tree.x3d tree.logo tree.vrm

 

Facebook Comments Box