Assignment 5 – Fractals

Maximum Points = 50

The purpose of this lab is to focus on the study of classes, objects, GUI, and recursion.

 

“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 11.7 shows several orders of Koch fractals. As the order increases, the shape begins to look like a snowflake. The applet shown in Listing 11.6 draws a Koch snowflake of several different 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.” [java Software Solutions 6th Edition, Lewis & Loftus, pg. 604]

 

Design and implement an applet that generalizes the KochSnowflake program.

 

1)       Allow the user to

                                                               i.      choose a fractal design from a menu item (must have at least three choices). The buttons to increase and decrease the order of the fractal will apply to whichever fractal design is chosen.

                                                              ii.      pick the background and drawing colors.

                                                            iii.      select the maximum number of iterations

b.       In addition to the Koch snowflake, include a C-curve fractal whose order 1 is a straight line. Each successive order is created   by replacing all line segments by two line segments, both half of the size of the original, and which meet at a right angle.            Specifically, a C-curve of order N from <x1, y1> to <x3, y3> is replaced by two C-curves from <x1, y1> to <x2, y2>  and from <x2, y2> to <x3, y3>  where:

 

x2 = (x1 + x3 + y1 - y3) / 2;

y2 = (y1 + y3 + x3 - x1) / 2;

 

c.        As a third type of fractal, include one where the original figure is a square (4 points) instead of an equilateral triangle (3 points) and the middle part of the line is being replaced by three-sides square. The two “middle” points (<x2,y2> and <x5,y5>) nearest the ends are 1/3 of the distance from its respective ends, while the two other two middle points can be found by:

         x3 = x2 + y2 - y5;

         y3 = y2 - x2 + x5;

         x4 = x5 + y5 - y6;

         y4 = y5 - x5 + x6;

 

d.       A Koch snowflake that starts with a square or pentagon instead of a triangle.

e.        Any other type of fractal that you would like to share.

               

Due before class on Thursday, April 9, 2009) Submit a .doc file containing the UML class diagram showing inheritance for all the classes used in your program. [10 pts]

(Due before class on Thursday, April 16, 2009) Submit your .java files containing your program to the dropbox in WebCT. [50 pts]

 Grades are determined using the following scale:

Grading Rubric  (Word document)