Fractal generation
The recursion can be applied to many various algorithms, also related to computer graphics. For this reason, let’s take a look at another example – fractal generation creating interesting patterns, such as the following:
Figure 9.4 – An exemplary fractal generated using the recursive function
It’s really beautiful, isn’t it? Can you see some tree patterns in this image? If not, let’s follow the bold line in the middle of the image (the tree trunk) and note that it is divided into two lines (branches), each rotated by a given degree. Then, follow one of these lines and see that it is divided according to the same rule. This process is applied further and further until the specified number of levels is reached.
The description of this recursive algorithm in the natural language is quite easy, so let’s take a look at code to calculate the coordinates of the start and end points of the...