Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- height of star: .054
- width of star: .03315789
- */
- import java.awt.Polygon;
- import javafx.application.Application;
- import javafx.collections.ObservableList;
- import javafx.scene.Scene;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- public class AmericanFlag extends Application {
- @Override // Override the start method in the Application class
- public void start(Stage primaryStage) {
- Pane pane = new Pane();
- final double FLAGWIDTH = 570;
- final double FLAGHEIGHT = 310;
- //create stripes
- for (int i = 0; i < 7; i++) {
- Rectangle stripe = new Rectangle();
- stripe.setX(10);
- stripe.widthProperty().bind(pane.widthProperty().subtract(20));
- stripe.yProperty().bind(pane.heightProperty().subtract(20).divide(13).multiply(2*i).add(10));
- stripe.heightProperty().bind(pane.heightProperty().subtract(20).divide(13.0));
- stripe.setFill(Color.RED);
- pane.getChildren().addAll(stripe);
- }
- //create blue rectangle
- Rectangle blue = new Rectangle();
- blue.setX(10);
- blue.setY(10);
- blue.widthProperty().bind(pane.widthProperty().subtract(20).multiply(0.4));
- blue.heightProperty().bind(pane.heightProperty().subtract(20).multiply(0.5385));
- blue.setFill(Color.BLUE);
- pane.getChildren().add(blue);
- for(int i=1;i<=10;i++)
- {
- if(i%2!=0)
- {
- for(int k=1;k<=12;k++)
- {
- Rectangle star = new Rectangle();
- star.xProperty().bind(blue.widthProperty().divide(12).multiply(2*k).add((blue.widthProperty().divide(12))));
- star.yProperty().bind(blue.heightProperty().divide(10));
- star.widthProperty().bind(blue.widthProperty().divide(12));
- star.heightProperty().bind(blue.heightProperty().divide(10));
- }
- }
- else
- {
- for(int k=1;k<=12;k++)
- {
- Rectangle star = new Rectangle();
- star.xProperty().bind(blue.widthProperty().divide(12).multiply(2*k).add((blue.widthProperty().divide(12))));
- star.yProperty().bind(blue.heightProperty().divide(10));
- star.widthProperty().bind(blue.widthProperty().divide(12));
- star.heightProperty().bind(blue.heightProperty().divide(10));
- }
- }
- }
- // Create a scene and place it in the stage
- Scene scene = new Scene(pane, FLAGWIDTH, FLAGHEIGHT);
- primaryStage.setTitle("American Flag");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- /*private Polygon getStar(double centerX, double centerY, double radius){
- //ObservableList<Double>list = polygon.getPoints();
- Polygon star = new Polygon();
- int outercircle = 18,innercircle = 54;
- for(int i=1;i<=10;i++){
- if(i%2!=0){
- star.addPoint(Integer.parseInt(radius*Math.cos(Math.toRadians(outercircle))),Integer.parseInt(radius*Math.sin(Math.toRadians(outercircle))));
- outercircle+=72;
- }
- else{
- }
- }
- }*/
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement