Java Reference
In-Depth Information
LISTING 12.7
continued
//-----------------------------------------------------------------
// Sets the fractal order to the value specified.
//-----------------------------------------------------------------
public void setOrder ( int order)
{
current = order;
}
//-----------------------------------------------------------------
// Returns the current order.
//-----------------------------------------------------------------
public int getOrder ()
{
return current;
}
}
The variable current represents the order of the fractal to be drawn. Each
recursive call to drawFractal decrements the order by 1. The base case of the
recursion occurs when the order of the fractal is 1, which results in a simple line
segment between the coordinates specified by the parameters.
If the order of the fractal is higher than 1, three additional points are computed.
In conjunction with the parameters, these points form the four line segments of
the modified fractal. Figure 12.8 shows the transformation.
Based on the position of the two end points of the original line segment, a point
one-third of the way and a point two-thirds of the way between them are com-
puted. The calculation of < x 3 , y 3 >, the point at the tip of the protrusion, is more
convoluted and uses a simplifying constant that incorporates multiple geometric
relationships. The calculations to determine the three new points actually have
nothing to do with the recursive technique used to draw the fractal, and so we
won't discuss the details of these computations here.
An interesting mathematical feature of a Koch snowflake is that it has an infi-
nite perimeter but a finite area. As the order of the fractal increases, the perimeter
grows exponentially larger, with a mathematical limit of infinity. However, a rect-
angle large enough to surround the second-order fractal for the Koch snowflake
is large enough to contain all higher-order fractals. The shape is restricted forever
in area, but its perimeter gets infinitely longer.
Search WWH ::




Custom Search