Java Reference
In-Depth Information
(a) Level 0
(b) Level 1
(c) Level 2
(d) Level 3
(e) Level 4
(f) Level 5
Fig. 18.12 | Koch Curve fractal.
We start with a straight line (Fig. 18.12(a)) and apply the pattern, creating a triangle
from the middle third (Fig. 18.12(b)). We then apply the pattern again to each straight
line, resulting in Fig. 18.12(c). Each time the pattern is applied, we say that the fractal is
at a new level , or depth (sometimes the term order is also used). Fractals can be displayed
at many levels—for instance, a fractal at level 3 has had three iterations of the pattern
applied (Fig. 18.12(d)). After only a few iterations, this fractal begins to look like a portion
of a snowflake (Fig. 18.12(e and f)). Since this is a strictly self-similar fractal, each portion
of it contains an exact copy of the fractal. In Fig. 18.12(f), for example, we've highlighted
a portion of the fractal with a dashed box. If the image in this box were increased in size,
it would look exactly like the entire fractal of part (f).
A similar fractal, the Koch Snowflake , is similar to the Koch Curve but begins with a
triangle rather than a line. The same pattern is applied to each side of the triangle, resulting
in an image that looks like an enclosed snowflake. For simplicity, we've chosen to focus
on the Koch Curve.
18.9.2 (Optional) Case Study: Lo Feather Fractal
We now demonstrate the use of recursion to draw fractals by writing a program to create a
strictly self-similar fractal. We call this the “Lo feather fractal,” named for Sin Han Lo, a De-
itel & Associates colleague who created it. The fractal will eventually resemble one-half of a
feather (see the outputs in Fig. 18.19). The base case, or fractal level of 0, begins as a line
between two points, A and B (Fig. 18.13). To create the next higher level, we find the mid-
point ( C ) of the line. To calculate the location of point C , use the following formula:
xC = (xA + xB) / 2 ;
yC = (yA + yB) / 2 ;
 
 
Search WWH ::




Custom Search