Question: For this part of the project, you will write a Java program that uses your shape classes to draw a fractal. Fractals are geometric patterns



For this part of the project, you will write a Java program that uses your shape classes to draw a fractal. Fractals are geometric patterns that repeat on themselves at smaller and smaller scales. They have been studied for centuries because of their interesting mathematical properties and often appear in natural objects (e.g. snow flakes, plants). Fractals are also a classic application of recursion; you can read more about fractals and their history here. Consider the example below, which illustrates the process of constructing a fractal composed of triangles at several steps in the process. Notice that at each step, triangles of increasingly smaller sizes are drawn at the three points of each existing triangle. More examples of fractals can be found in Section 5. To help you with the drawing, we've already implemented a Canvas class that supports all of the drawing capability you need. You should look at the code if you're interested, but all you'll need to know is how you can interact with Canvas objects. Here are the method specifications of the Canvas class: - Canvas() (default constructor): creates drawing of default size - Canvas(int height, int width): creates drawing of specified width and height - void drawShape(Circle circleObj) - void drawShape(Rectangle rectangleObj) - void drawShape(Triangle triangleObj) Each of the drawing methods will draw the shape you pass it in the specified location and in the specified color. Here's an example of how you might use the Canvas class to draw a single blue circle: Canvas drawing = new Canvas(800,800); Circle myCircle = new Circle(0,0,100); myCircle.setColor (Color.BLUE); drawing.drawShape(myCircle); Note: When you compile the Canvas. java class, you may have noticed that you receive the following warning (or something similar): Note: Canvas.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. The provided Canvas class uses the deprecated JApplet class. You can ignore this warning, and it does not indicate that anything is wrong with your code. You will be responsible for filling in the FractalDrawer class. For full credit, your program should have the following features: - Ask the user for input (choices: "circle", "triangle", or "rectangle") and use the corresponding shape as the base of your fractal. - Draw a pattern that repeats on itself at least 7 times and uses a new color in each repetition (feel free to be creative - you can cycle colors or choose colors at random, as long as overlapping shapes are distinct from one another). IMPORTANT: The pattern must repeat on itself using recursion for full credit. Changing a shape's size or position should be involved in recursive calls. - Draw at least four shapes per layer for rectangles and circles and at least three per layer for triangles (e.g. draw the new shapes on all three points or sides of a triangle, or on four opposite sides of a circle - again, feel free to be creative). - Compute the total area of all shapes that form your fractal and print the result to the screen after your program is finished drawing. You do not need to take into account any overlap, simply sum the area of all the shapes that were drawn, even if they overlap each other. To receive full credit, your program will need to be able to draw a fractal using recursion for all three possible inputs (circle, triangle, or rectangle). We suggest that the most convenient implementation is to simply implement three different methods, one that draws a circle fractal, one that draws a triangle fractal, and one that draws a rectangle fractal. Note: If nothing appears on the canvas when you run your program, or of only a partial fractal appears, try resizing the canvas window. If you need to do this to display the entire fractal, you will not be penalized. The TAs are aware that many fractals will only appear after resizing the window
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
