Create a JavaFX application that will draw a fractal curve using line segments. Fractals are recursively defined
Question:
Create a JavaFX application 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 p and p :
To draw the curve from p to p , 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 p and p 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 p to p . 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.
Step by Step Answer:
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch