Java Reference
In-Depth Information
method, with parameters that scale the picture to the correct size and location.
The drawPictures method is then called recursively to draw the upper-left
quadrant.
On each invocation, if the drawing area is large enough, the drawPictures
method is invoked again, using a smaller drawing area. Eventually, the drawing
area becomes so small that the recursive call is not performed. Note that draw-
Pictures assumes the origin (0, 0) coordinate as the relative location of the new
images, no matter what their size is.
The base case of the recursion in this problem specifies a minimum size for the
drawing area. Because the size is decreased each time, the base case eventually is
reached and the recursion stops. This is why the upper-left corner is empty in the
smallest version of the collage.
Fractals
A fractal is a geometric shape that can be made up of the
same pattern repeated at different scales and orientations.
The nature of a fractal lends itself to a recursive definition.
Interest in fractals has grown immensely in recent years,
largely due to Benoit Mandelbrot, a Polish mathematician
born in 1924. He demonstrated that fractals occur in many
places in mathematics and nature. Computers have made fractals much easier to
generate and investigate. Over the past quarter century, the bright, interesting
images that can be created with fractals have come to be considered as much an
art form as a mathematical interest.
One particular example of a fractal is called the Koch snowflake, named after
Helge von Koch, a Swedish mathematician. It begins with an equilateral triangle,
which is considered to be the Koch fractal of order 1. Koch fractals of higher
orders are constructed by repeatedly modifying all of the line segments in the
shape.
To create the next higher order Koch fractal, each line segment in the shape is
modified by replacing its middle third with a sharp protrusion made of two line
segments, each having the same length as the replaced part. Relative to the entire
shape, the protrusion on any line segment always points outward. Figure 12.7
shows several orders of Koch fractals. As the order increases, the shape begins to
look like a snowflake.
The applet shown in Listing 12.6 draws a Koch snowflake of several differ-
ent orders. The buttons at the top of the applet allow the user to increase and
decrease the order of the fractal. Each time a button is pressed, the fractal image
is redrawn. The applet serves as the listener for the buttons.
KEY CONCEPT
A fractal is a geometric shape that
is defined naturally in a recursive
manner.
 
Search WWH ::




Custom Search