Question

Create a FRACTAL Javafx program ; it should draw some kind of fractal image ( a...

Create a FRACTAL Javafx program ; it should draw some kind of fractal image ( a pattern that repeats).

.... you can start with code similar to this (but I DO NOT want you just doing this simple one.. do a more complex image)

//call the following method from your start() method after you create an empty pane (start with your drawHouse code that you did last week):

Pane pane = new Pane(); //create an empty pane
drawCircle(pane, 50,50, 20);  //draw circles or some recursive pattern on that pane

//recursive method

void drawCircle(Pane p, int x, int y, float radius)

  {
    Circle oval = new Circle(x, y, radius);
    oval.setFill(null);  //if just want outlines, then use this line!
    oval.setStroke(Color.RED);
    
    p.getChildren().addAll(oval); //magic line to add new oval to pane
    
  if(radius > 2) {
  radius *= 0.75f;
  // The drawCircle() function is calling itself recursively.
      drawCircle(p, x, y, radius);
  }
    
}//end drawCircle

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: The code is highly customizable. Read the comments to learn where do you want to modify the code to get different results.

// DrawFractal.java

import javafx.application.Application;

import static javafx.application.Application.launch;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.scene.shape.Line;

import javafx.stage.Stage;

public class DrawFractal extends Application {

    @Override

    public void start(Stage primaryStage) {

        Pane pane = new Pane(); //create an empty pane

        //drawing a fractal on pane, at center (300,300) with radius of inner most circle: 30 and level: 4

        //note: experiment with the last value (level), either increase or decrease it to see how the image changes

        //please do not provide large numbers as levels. keep it under 5 or 6

        drawFractal(pane, 300, 300, 30, 4);

        //setting up and displaying a scene

        Scene scene = new Scene(pane, 600, 600);

       primaryStage.setScene(scene);

        primaryStage.setTitle("Fractals");

        primaryStage.show();

    }

   

    //recursive method to draw fractals

    void drawFractal(Pane p, double x, double y, double radius, int levels) {

        //if levels go negative, we stop. this is the base condition

        if (levels < 0) {

            return;

        }

        //checking if levels > 0,

        if (levels > 0) {

            //we will divide a circle (360 degree) into connections number of points

            int connections = 3; //experiment with this value also, make it 4 or 5 or 2

            //looping for connections number of times

            for (int i = 0; i < connections; i++) {

                //finding angle of rotation

              double angle = i * (360.0 / connections);

                //finding a coordinate which is 4 * radius distance away from center coordinates

                //x,y at angle degrees, using basic trigonometry.

                double xx = x + (4 * radius) * Math.cos(Math.toRadians(angle));

                double yy = y + (4 * radius) * Math.sin(Math.toRadians(angle));

                //creating a line from x,y to xx,yy

                Line line = new Line(x, y, xx, yy);

                //adding to pane

                p.getChildren().add(line);

                //making a recursive call to drawFractal, passing this new point as new x,y

                //and half the radius as new radius, and most importantly, one less level

                drawFractal(p, xx, yy, radius / 2.0, levels - 1);

            }

        }

        //finally we create a circle with radius at x,y position, and add to the pane.

        //we are drawing the circle at the end, to prevent the lines from being drawn over the circles

      Circle oval = new Circle(x, y, radius);

        oval.setFill(Color.GRAY); //if just want outlines, then use this line!

        oval.setStroke(Color.BLACK);

        p.getChildren().addAll(oval); //magic line to add new oval to pane

    }//end drawCircle

    public static void main(String[] args) {

        launch(args);

    }

}

/*OUTPUT*/


X

Add a comment
Know the answer?
Add Answer to:
Create a FRACTAL Javafx program ; it should draw some kind of fractal image ( a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function...

    PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function def fractal(length, spaces). This function will print out a certain number of stars * and spaces. If length is 1 print out the number of spaces given followed by 1 star. If the length is greater than one do the following: Print the fractal pattern with half the length and the same number of spaces. Print the number of spaces given followed by length...

  • /* * File: HFractal.cpp * ------------------ * This program draws an H-fractal on the graphics wi...

    /* * File: HFractal.cpp * ------------------ * This program draws an H-fractal on the graphics window.int main() { */ #include "gwindow.h" /* Function prototypes */ void drawHFractal(GWindow & gw, double x, double y, double size, int order); /* Main program */ int main() { GWindow gw; double xc = gw.getWidth() / 2; double yc = gw.getHeight() / 2; drawHFractal(gw, xc, yc, 100, 3); return 0; } /* * Function: drawHFractal * Usage: drawHFractal(gw, x, y, size, order); * ------------------------------------------- *...

  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

  • Write a JavaFX application that displays 10,000 very small circles (radius of 1 pixel) in random...

    Write a JavaFX application that displays 10,000 very small circles (radius of 1 pixel) in random locations within the visible area. Fill the dots on the left half of the scene red and the dots on the right half of the scene green. Use the getWidth method of the scene to help determine the halfway point. This is what I have so far: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.shape.Circle; import javafx.scene.paint.Color; import javafx.stage.Stage; import java.util.Random; import javafx.scene.Group; public class Class615...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

  • JavaFX program - Add a second level to the game. //Main game object/class package main; import java.util.ArrayList; impo...

    JavaFX program - Add a second level to the game. //Main game object/class package main; import java.util.ArrayList; import javafx.animation.AnimationTimer; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class Game extends Pane implements Runnable {       // instance variables    private ArrayList<MOB> mobs;    private ArrayList<Rectangle> hitBoxes;    private ArrayList<Treasure> treasure;    private Player player;    private final ImageView background = new ImageView();    private Level level;    private SimpleIntegerProperty score;    private...

  • JAVAFX ONLY PROGRAM!!!!! SORTING WITH NESTED CLASSES AND LAMBDA EXPRESSIONS. DIRECTIONS ARE BELOW: DIRECTIONS: The main...

    JAVAFX ONLY PROGRAM!!!!! SORTING WITH NESTED CLASSES AND LAMBDA EXPRESSIONS. DIRECTIONS ARE BELOW: DIRECTIONS: The main point of the exercise is to demonstrate your ability to use various types of nested classes. Of course, sorting is important as well, but you don’t really need to do much more than create the class that does the comparison. In general, I like giving you some latitude in how you design and implement your projects. However, for this assignment, each piece is very...

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • HW60.1. Array Quicksort You've done partition so now it's time to finish Quicksort. Create a publ...

    HW60.1. Array Quicksort You've done partition so now it's time to finish Quicksort. Create a public non-final class named Quicksort that extends Partitioner. Implement a public static method void quicksort (int] values) that sorts the input array of ints in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. You should sort the array in place, which is why your function is declared to return void. If...

  • Using JAVA FX how would I combine the two programs below into one interface that allows...

    Using JAVA FX how would I combine the two programs below into one interface that allows the user to pick which specific program they would like to play. They should be able to choose which one they want to play and then switch between them if necesary. All of this must be done in JAVA FX code Black jack javafx - first game program package application; import java.util.Arrays; import java.util.ArrayList; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.Insets;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT