# Recursive 2D fern leaf procedure

• Sharebar

In my previous blog, I explained about a recursive tree procedure. Here is another one borrowed from Joshua's Logo Interpreter example: fern leaf procedure. This fern leaf procedure creates a 2D fern leaf in VRMath2's 3D space. You can examine it below in the 3D space with the LOGO program.

The TO (line:3) and END (line: 11) mark the start and end of this fern procedure. The fern procedure takes two inputs. The first input is :size of the fern leaf. This parameter also serves as the exiting condition for this recursion (:size < 1 in line: 4). The second input is a :sign as positive 1 or negative 1. This :sign inverses during the recursive calls and in fact changes the turning direction. For example, if :sign is -1, then RT 70 * :sign is effectively the same as LT 70.

In line 18 of the program, fern 16 1, in that the 16 results in 16 sections of a left branch and a right branch on the main stem. This can also be seen from line 9, where :size is reduced by 1 for each recursion. For each recursive branch, the :size is reduced by half (line: 6 and 8, where :size * 0.5). A command JB (line: 10) is used to JumpBack the turtle without leaving a track.

After the procedure from line 12, I have added comments for each of the commands. Because I want to make the fern leaf green color, therefore in line 14, I turn the next pen color off using NCOFF command, then SETPCNAME "green to set the pen color to green. The double quote sign " in LOGO language is a special sign to mean that the word next to it is a LOGO Word or a string. At the moment, I have not written the documentation about LOGO language in VRMath2 site, but that is the convention in all LOGO languages. You may refer to the Berkeley Logo Reference Manual if you wish for more details.

Since VRMath2 has a 3D space, we should be able to modify the existing procedures to create proper 3D objects. Please give me your comments on how you can make this fern leaf curly in 3D space.

### Curled fern

So, after much consideration, I have made 2 small changes to line  9 of the code. These changes allows the fern to curl down

curled_fern.x3d

the larger the angle used the curlier the result.

angle: 10      angle: 25

### This is cool...

Now this 2D fern leaf has become a 3D fern leaf....

I noticed that every branch has curled 10 degrees. Wow, you should write a blog about it.