Advertisement
Guest User

Flag Pane

a guest
Mar 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.97 KB | None | 0 0
  1. import javafx.collections.ObservableList;
  2. import javafx.scene.layout.Pane;
  3. import javafx.scene.paint.Color;
  4. import javafx.scene.shape.Polygon;
  5. import javafx.scene.shape.Rectangle;
  6.  
  7. class FlagPane extends Pane {
  8.     private void paint() {
  9.         this.getChildren().clear();
  10.         for (int i = 0; i < 7; i++) {
  11.             Rectangle r = new Rectangle();
  12.             r.setX(10);
  13.             r.setWidth(getWidth() - 20);
  14.             r.setHeight((getHeight() - 20) / 13.0);
  15.             r.setY((getHeight() - 20) / 13.0 * (2 * i) + 10);
  16.             r.setFill(Color.RED);
  17.             this.getChildren().add(r);
  18.         }
  19.         Rectangle b = new Rectangle();
  20.         b.setX(10);
  21.         b.setWidth((getWidth()-20) * .39);
  22.         b.setHeight((getHeight()-20) * (.5385));
  23.         b.setY(10);
  24.         b.setFill(Color.BLUE);
  25.         this.getChildren().add(b);
  26.        
  27.         Polygon t = new Polygon();
  28.         for (int i = 1; i < 12; i++) {
  29.             if (i > 1){
  30.                 i = i + 1;
  31.             }
  32.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (.054),5);
  33.         }
  34.         for (int i = 1; i < 11; i++) {
  35.             if (i > 1){
  36.                 i = i + 1;
  37.             }
  38.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (3 * .054),5);
  39.         }
  40.         for (int i = 1; i < 11; i++) {
  41.             if (i > 1){
  42.                 i = i + 1;
  43.             }
  44.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (5 * .054),5);
  45.         }
  46.         for (int i = 1; i < 11; i++) {
  47.             if (i > 1){
  48.                 i = i + 1;
  49.             }
  50.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (7 * .054),5);
  51.         }
  52.         for (int i = 1; i < 11; i++) {
  53.             if (i > 1){
  54.                 i = i + 1;
  55.             }
  56.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (9 * .054),5);
  57.         }
  58.         for (int i = 2; i < 11; i++) {
  59.             if (i > 2){
  60.                 i = i + 1;
  61.             }
  62.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (2 * .054),5);
  63.         }
  64.         for (int i = 2; i < 11; i++) {
  65.             if (i > 2){
  66.                 i = i + 1;
  67.             }
  68.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (4 * .054),5);
  69.         }
  70.         for (int i = 2; i < 11; i++) {
  71.             if (i > 2){
  72.                 i = i + 1;
  73.             }
  74.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (6 * .054),5);
  75.         }
  76.         for (int i = 2; i < 11; i++) {
  77.             if (i > 2){
  78.                 i = i + 1;
  79.             }
  80.             t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (8 * .054),5);
  81.         }
  82.     }
  83.         private Polygon getStar (double cx, double cy, double radius){
  84.         Polygon p = new Polygon();
  85.         ObservableList<Double> list = p.getPoints();
  86.         list.add(cx + radius * Math.cos(Math.toRadians(18)));
  87.         list.add(cy - radius * Math.sin(Math.toRadians(18)));
  88.         list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(72)));
  89.         list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(72)));
  90.         list.add(cx + radius * Math.cos(Math.toRadians(90)));
  91.         list.add(cy - radius * Math.sin(Math.toRadians(90)));
  92.         list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(108)));
  93.         list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(108)));
  94.         list.add(cx + radius * Math.cos(Math.toRadians(162)));
  95.         list.add(cy - radius * Math.sin(Math.toRadians(162)));
  96.         list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(180)));
  97.         list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(180)));
  98.         list.add(cx + radius * Math.cos(Math.toRadians(234)));
  99.         list.add(cy - radius * Math.sin(Math.toRadians(234)));
  100.         list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(270)));
  101.         list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(270)));
  102.         list.add(cx + radius * Math.cos(Math.toRadians(306)));
  103.         list.add(cy - radius * Math.sin(Math.toRadians(306)));
  104.         list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(360)));
  105.         list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(360)));
  106.         list.add(cx + radius * Math.cos(Math.toRadians(378)));
  107.         list.add(cy - radius * Math.sin(Math.toRadians(378)));
  108.        
  109.         p.setFill(Color.WHITE);
  110.         p.setStroke(Color.WHITE);
  111.         this.getChildren().add(p);
  112.        
  113.         return p;
  114.        
  115.     }
  116.    
  117.  
  118.     @Override
  119.     public void setWidth(double width) {
  120.         super.setWidth(width);
  121.         paint();
  122.     }
  123.  
  124.     @Override
  125.     public void setHeight(double height) {
  126.         super.setHeight(height);
  127.         paint();
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement