H-Tree
A fractal is an infinitely repeated pattern that is self-similar across
different scales. Let us now construct a fractal called an H-tree with the
help of a computer. As the name suggests, it is called H-tree because it
has a basic motif of an H-like shape
To begin, and at level 1, we draw an H with points A, B, C, D, E, F, O where
O is the center point. The length of CD equals to that of AE and BF. Next,
at level 2, we draw a new H pattern with A, B, E, F as the center points,
respectively. And the side length of this new H pattern is reduced by half.
And the pattern continues.
Due to this repeated nature, we can leverage recursion to draw H-trees on
a computer. The recursion stops when the desired level is achieved. Inside
the recursion function, we can keep track of the coordinates of points A, B,
C, D, E, F, and O, which are calculated using a length parameter, and
update the coordinates values upon a change of the level. For
visualization, we can use the matplotlib package to draw a line to connect
two points. The amount by which the length is reduced is controlled by the
factor parameter. Here, the default value of factor is 4, i.e., reduce the
length by half at each iteration.
OUTPUT-