The H-Tree

The H-Tree is one of the simpler fractals to understand and program. You begin by drawing a vertical line with two (shorter) horizontal 'legs' like a sideways H (Figure 1). Then, at the ends of each 'leg', draw the same shape, rescaled.(Figure 2). The process continues until the line segments are too small to draw. The result is a grid-like image. (Figure 3).

Figure 1
Figure 2
Figure N

To draw the H-Tree, you need the horizontal coordinate of the central segment and the y coordinates of the two endpoints. You also need a ratio to specify the lengths of the 'legs' relative to the length of the central segment. So, the signature for your recursive method might look like this:

public void drawH(int x1, int y1, int y2, double ratio)

where (x1, y1) and (x1, y2) are the coordinates of the endpoints of the central segment and ratio is the relative length of each leg.

The above images were generated with a ratio of 0.5. Experiment with different ratios to see the effects!