Create an application in a JavaFX GUI that will draw a fractal curve using line segments. Fractals are recursively defined curves. The curve you will draw is based on a line segment between points p1 and p2: To draw the curve from p1 to p2, you first split the segment into thirds. Then add two segments and offset the middle segment to form part of a square, as shown in the following picture:
Note that you would not draw the arrowheads, but we use them here to indicate the direction of drawing. If the order of p1 and p2 were reversed, the square would be below the original line segment. This process is recursive and is applied to each of the five new line segments, resulting in the following curve: The fractal is given by repeating this recursive process an infinite number of times. Of course, we will not want to do that and will stop the process after a certain number of times.
To draw this curve, use a recursive method drawFractal(p1x, p1y, p2x, p2y, k). If k is zero, just draw a line from p1 to p2. Otherwise, split the line segment into five segments, as described previously, and recursively call drawFractal for each of these five segments. Use k - 1 for the last argument in the recursive calls.
For convenience, you may assume that the segments are either vertical or horizontal. The initial call should be drawFractal(50, 800, 779, 800, 5). Set the size of the window to 1000 by 1000.
The hardest part of this recursive algorithm is getting arguments of recursive calls for each segment correct. Part of the complication is that Java’s coordinate system has y positive in the downward direction. One can work on the horizontal case first and then do the vertical. It is recommended that k=1 be used when developing the algorithm as well.
See the code in Fractal.java.
You might also like to view...
How many members (data and functions) does the following class have?How many members (data and functions) does the following class have?
class Rational { public: Rational(); Rational(int numer, int denom); Rational(int whole); int getNumerator(); int getDenominator(); friend void display(ostream& out, const Rational& value); private: int numerator; int denominator; }; a. 2 b. 6 c. 5 d. 7 e. 8
Which of these characteristics is most important to a systems analyst?
A) communicator B) problem solver C) programmer D) project manager
If a disk pool becomes full, how does Windows Server 2012 respond?
A. More space is automatically provisioned from available drives in the primordial pool B. Affected volumes are marked as read-only until more space is provisioned C. The disk pool is moved to an offline state until more physical storage is added D. The server notifies all users with data in the disk pool in order to encourage data cleaning activities
Not common on contemporary architectures, ___________ requires only one memory reference and no special calculation, but provides only a limited address space.
Fill in the blank(s) with the appropriate word(s).