Question

WRITE A JavaFX APPLICATION THAT DRAWS A PICTURE OF A FLOWER. Use thick lines for stalks...

WRITE A JavaFX APPLICATION THAT DRAWS A PICTURE OF A FLOWER.
Use thick lines for stalks and rotated ellipses for petals. Put the sky and the ground as background. Don’t worry artistic quality, it should look simple. It should take about 45 to 75 statements.
Also, have some line-by-line documentation that says what is going on, e.g., // draw petal // draw ground // draw leaf

The snowman program should be used as a GUIDE.
Snowman code :

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SnowmanFX extends Application
{
public void start( Stage primaryStage )
{
Ellipse base = new Ellipse( 80, 210, 80, 60 );
base.setFill( Color.WHITE );
Ellipse middle = new Ellipse( 80, 130, 60, 40 );
middle.setFill( Color.WHITE );
Circle head = new Circle( 80, 70, 30 );
head.setFill( Color.WHITE );
  
Circle rightEye = new Circle( 70, 60, 5 );
rightEye.setFill( Color.BLACK );
Circle leftEye = new Circle( 90, 60, 5 );
leftEye.setFill( Color.BLACK );
Line mouth = new Line( 70, 80, 90, 80 );
  
Circle topButton = new Circle( 80, 120, 6 ) ;
topButton.setFill( Color.RED );
Circle botButton = new Circle( 80, 140, 6 ) ;
botButton.setFill( Color.RED );
  
Line leftArm = new Line( 110, 130, 160, 130 );
leftArm.setStrokeWidth( 3 );
Line rightArm = new Line( 50, 130, 0, 100 );
rightArm.setStrokeWidth( 3 );
  
Rectangle stovepipe = new Rectangle( 60, 0, 40, 50 );
Rectangle brim = new Rectangle( 50, 45, 60, 5 );
Group hat = new Group( stovepipe, brim );
hat.setRotate( 15 );
hat.setTranslateX( 10 );
  
Group body = new Group( base, middle, head );
Group face = new Group( leftEye, rightEye, mouth );
Group buttons = new Group( topButton, botButton );
Group arms = new Group( leftArm, rightArm );
  
Group snowman = new Group( body, face, buttons, arms, hat );
snowman.setTranslateX( 170 );
snowman.setTranslateY( 50 );
  
Circle sun = new Circle( 0, 0, 30 );
sun.setFill( Color.GOLD );
sun.setTranslateX( 60 );
sun.setTranslateY( 60 );
  
Rectangle ground = new Rectangle( 0, 250, 500, 100 );
ground.setFill( Color.STEELBLUE );
  
Group root = new Group( ground, sun, snowman );
  
Scene scene = new Scene( root, 500, 350, Color.LIGHTBLUE );
  
primaryStage.setTitle( "Snowman" );
primaryStage.setScene( scene );
primaryStage.show();
}
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

FlowerFX.java

package application;

import java.util.ArrayList;
import java.util.List;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.PickResult;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class FlowerFX extends Application {

   public Group petalLayer(int x, int y, int angleOffset) {
       List<Node> petals = new ArrayList<>();
       for (int i = angleOffset; i < 360; i += 120) {
           Ellipse petal = new Ellipse(5, 5, 100, 30);
           petal.setFill(Color.YELLOW);
           petal.setRotate(i);
           petals.add(petal);
       }
       Group flower = new Group(petals);
       flower.setTranslateX(x);
       flower.setTranslateY(y);

       petals = new ArrayList<>();
       for (int i = angleOffset; i < 360; i += 120) {
           Ellipse petal = new Ellipse(5, 5, 100, 30);
           petal.setFill(null);
           petal.setStroke(Color.BLACK);
           petal.setStrokeWidth(1);
           petal.setRotate(i);
           petals.add(petal);
       }
       Group flower_border = new Group(petals);
       flower_border.setTranslateX(x);
       flower_border.setTranslateY(y);
      
       Ellipse petal = new Ellipse(5, 5, 40, 40);
       petal.setFill(Color.DARKRED);
       petal.setStroke(Color.BLACK);
       petal.setStrokeWidth(1);
       petal.setTranslateX(x);
       petal.setTranslateY(y);
      

       return new Group(flower, flower_border, petal);
   }
  
   Group flower(int x, int y, int size) {
       List<Node> petals = new ArrayList<>();
       Line line = new Line(x+5, y+5, 150, 400);
       line.setStrokeWidth(5);
       line.setStroke(Color.DARKGREEN);
       petals.add(line);
       petals.add(petalLayer(x, y, 0));
       Group flower = new Group(petals);
       flower.setTranslateX(x);
       flower.setTranslateY(y);
       return new Group(petals);
   }

   public void start(Stage primaryStage) {

       Circle sun = new Circle(0, 0, 30);
       sun.setFill(Color.GOLD);
       sun.setTranslateX(60);
       sun.setTranslateY(60);

       Rectangle ground = new Rectangle(0, 250, 500, 100);
       ground.setFill(Color.STEELBLUE);

       Group root = new Group(ground, sun, flower(245, 145, 120));

       Scene scene = new Scene(root, 500, 350, Color.LIGHTBLUE);

       primaryStage.setTitle("Snowman");
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}

Add a comment
Know the answer?
Add Answer to:
WRITE A JavaFX APPLICATION THAT DRAWS A PICTURE OF A FLOWER. Use thick lines for stalks...
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
  • changes needed is at the end of the code //************************************************************************ // Snowman.java Author: Lewis/Loftus // //...

    changes needed is at the end of the code //************************************************************************ // Snowman.java Author: Lewis/Loftus // // Demonstrates the translation of a set of shapes. //************************************************************************ import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.*; public class Snowman extends Application { //-------------------------------------------------------------------- // Presents a snowman scene. //-------------------------------------------------------------------- public void start(Stage primaryStage) { Ellipse base = new Ellipse(80, 210, 80, 60); base.setFill(Color.WHITE);    Ellipse middle = new Ellipse(80, 130, 50, 40); middle.setFill(Color.WHITE);    Circle head = new Circle(80,...

  • 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...

  • Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees...

    Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F - 32)*5/9). It needs to be JavaFX 1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.layout.HBox; 5 import javafx.scene.layout. VBox; 6 import javafx.geometry.Pos; 7 import javafx.geometry.Insets; 8 import javafx.scene.control.Label; 9 import javafx.scene.control. TextField; 10 import javafx.scene.control.Button; 11 import javafx.event. EventHandler; 12 import javafx.event. ActionEvent; 13 14 ** 15 * Kilometer Converter application 16 17 18 public...

  • Please read the article bellow and discuss the shift in the company's approach to genetic analysis....

    Please read the article bellow and discuss the shift in the company's approach to genetic analysis. Please also discuss what you think about personal genomic companies' approaches to research. Feel free to compare 23andMe's polices on research with another company's. Did you think the FDA was right in prohibiting 23andMe from providing health information? These are some sample talking points to get you thinking about the ethics of genetic research in the context of Big Data. You don't have to...

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