Write a program that draws a square fractal. Fractals are images that keep repeating their own image in ever-smaller versions. There exists numerous fractals and some fractals rely on computation of advanced mathematics. All fractals have a recursive quality and provide an ideal platform for practicing recursive concepts. You will note that from the four corners of the center rectangle, smaller rectangles are drawn and each rectangle in turn continues to draw three smaller rectangles until the rectangle is the size of one pixel. A CODE TEMPLATE & PICTURE OF OUTPUT IS ALREADY PROVIDED IN THE ATTACHED PICTURES Method drawSquare1 gets the ball rolling and draws a solid rectangle in the center of the screen. The initial rectangle needs to be 1/4 the size of the monitor. This explains why it is important to know the screen resolution and why this information is passed by parameter. Method drawSquare1 needs to make four method calls to draw each one of the four rectangles attached to the initial rectangle. Each one of the succeeding rectangles is half the width and height of the preceding rectangle. The delay method is provided so that you can observe the recursive sequence as the fractal picture is drawn. You need to experiment with the delay value, which depends on the speed of your computer. It is often the case that the applet window size is smaller than the monitor resolution. If such is the case use the applet window resolution values in the paint method.
Write a program that draws a square fractal. Fractals are images that keep repeating their own image in ever-smaller versions. There exists numerous fractals and some fractals rely on computation of advanced mathematics. All fractals have a recursive quality and provide an ideal platform for practicing recursive concepts. You will note that from the four corners of the center rectangle, smaller rectangles are drawn and each rectangle in turn continues to draw three smaller rectangles until the rectangle is the size of one pixel.
A CODE TEMPLATE & PICTURE OF OUTPUT IS ALREADY PROVIDED IN THE ATTACHED PICTURES
Method drawSquare1 gets the ball rolling and draws a solid rectangle in the center of the screen. The initial rectangle needs to be 1/4 the size of the monitor. This explains why it is important to know the screen resolution and why this information is passed by parameter. Method drawSquare1 needs to make four method calls to draw each one of the four rectangles attached to the initial rectangle. Each one of the succeeding rectangles is half the width and height of the preceding rectangle. The delay method is provided so that you can observe the recursive sequence as the fractal picture is drawn. You need to experiment with the delay value, which depends on the speed of your computer. It is often the case that the applet window size is smaller than the monitor resolution. If such is the case use the applet window resolution values in the paint method.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images