Advertisement
zakjag

Fx Flax progress

Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /*
  2. height of star: .054
  3. width of star: .03315789
  4. */
  5. import java.awt.Polygon;
  6.  
  7. import javafx.application.Application;
  8. import javafx.collections.ObservableList;
  9. import javafx.scene.Scene;
  10. import javafx.scene.layout.Pane;
  11. import javafx.scene.paint.Color;
  12. import javafx.scene.shape.Rectangle;
  13. import javafx.stage.Stage;
  14.  
  15. public class AmericanFlag extends Application {
  16. @Override // Override the start method in the Application class
  17. public void start(Stage primaryStage) {
  18. Pane pane = new Pane();
  19. final double FLAGWIDTH = 570;
  20. final double FLAGHEIGHT = 310;
  21.  
  22. //create stripes
  23. for (int i = 0; i < 7; i++) {
  24. Rectangle stripe = new Rectangle();
  25. stripe.setX(10);
  26. stripe.widthProperty().bind(pane.widthProperty().subtract(20));
  27. stripe.yProperty().bind(pane.heightProperty().subtract(20).divide(13).multiply(2*i).add(10));
  28. stripe.heightProperty().bind(pane.heightProperty().subtract(20).divide(13.0));
  29. stripe.setFill(Color.RED);
  30. pane.getChildren().addAll(stripe);
  31. }
  32. //create blue rectangle
  33. Rectangle blue = new Rectangle();
  34. blue.setX(10);
  35. blue.setY(10);
  36. blue.widthProperty().bind(pane.widthProperty().subtract(20).multiply(0.4));
  37. blue.heightProperty().bind(pane.heightProperty().subtract(20).multiply(0.5385));
  38. blue.setFill(Color.BLUE);
  39. pane.getChildren().add(blue);
  40.  
  41. for(int i=1;i<=10;i++)
  42. {
  43. if(i%2!=0)
  44. {
  45. for(int k=1;k<=12;k++)
  46. {
  47. Rectangle star = new Rectangle();
  48. star.xProperty().bind(blue.widthProperty().divide(12).multiply(2*k).add((blue.widthProperty().divide(12))));
  49. star.yProperty().bind(blue.heightProperty().divide(10));
  50. star.widthProperty().bind(blue.widthProperty().divide(12));
  51. star.heightProperty().bind(blue.heightProperty().divide(10));
  52. }
  53. }
  54. else
  55. {
  56. for(int k=1;k<=12;k++)
  57. {
  58. Rectangle star = new Rectangle();
  59. star.xProperty().bind(blue.widthProperty().divide(12).multiply(2*k).add((blue.widthProperty().divide(12))));
  60. star.yProperty().bind(blue.heightProperty().divide(10));
  61. star.widthProperty().bind(blue.widthProperty().divide(12));
  62. star.heightProperty().bind(blue.heightProperty().divide(10));
  63. }
  64.  
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. // Create a scene and place it in the stage
  75. Scene scene = new Scene(pane, FLAGWIDTH, FLAGHEIGHT);
  76. primaryStage.setTitle("American Flag");
  77. primaryStage.setScene(scene);
  78. primaryStage.show();
  79. }
  80.  
  81. /*private Polygon getStar(double centerX, double centerY, double radius){
  82. //ObservableList<Double>list = polygon.getPoints();
  83. Polygon star = new Polygon();
  84. int outercircle = 18,innercircle = 54;
  85. for(int i=1;i<=10;i++){
  86. if(i%2!=0){
  87. star.addPoint(Integer.parseInt(radius*Math.cos(Math.toRadians(outercircle))),Integer.parseInt(radius*Math.sin(Math.toRadians(outercircle))));
  88. outercircle+=72;
  89. }
  90. else{
  91.  
  92. }
  93. }
  94. }*/
  95.  
  96. public static void main(String[] args) {
  97. launch(args);
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement