Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.collections.ObservableList;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Polygon;
- import javafx.scene.shape.Rectangle;
- class FlagPane extends Pane {
- private void paint() {
- this.getChildren().clear();
- for (int i = 0; i < 7; i++) {
- Rectangle r = new Rectangle();
- r.setX(10);
- r.setWidth(getWidth() - 20);
- r.setHeight((getHeight() - 20) / 13.0);
- r.setY((getHeight() - 20) / 13.0 * (2 * i) + 10);
- r.setFill(Color.RED);
- this.getChildren().add(r);
- }
- Rectangle b = new Rectangle();
- b.setX(10);
- b.setWidth((getWidth()-20) * .39);
- b.setHeight((getHeight()-20) * (.5385));
- b.setY(10);
- b.setFill(Color.BLUE);
- this.getChildren().add(b);
- Polygon t = new Polygon();
- for (int i = 1; i < 12; i++) {
- if (i > 1){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (.054),5);
- }
- for (int i = 1; i < 11; i++) {
- if (i > 1){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (3 * .054),5);
- }
- for (int i = 1; i < 11; i++) {
- if (i > 1){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (5 * .054),5);
- }
- for (int i = 1; i < 11; i++) {
- if (i > 1){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (7 * .054),5);
- }
- for (int i = 1; i < 11; i++) {
- if (i > 1){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (9 * .054),5);
- }
- for (int i = 2; i < 11; i++) {
- if (i > 2){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (2 * .054),5);
- }
- for (int i = 2; i < 11; i++) {
- if (i > 2){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (4 * .054),5);
- }
- for (int i = 2; i < 11; i++) {
- if (i > 2){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (6 * .054),5);
- }
- for (int i = 2; i < 11; i++) {
- if (i > 2){
- i = i + 1;
- }
- t = getStar((getWidth() - 20) * (i*(.063/1.9)),(getHeight() - 20) * (8 * .054),5);
- }
- }
- private Polygon getStar (double cx, double cy, double radius){
- Polygon p = new Polygon();
- ObservableList<Double> list = p.getPoints();
- list.add(cx + radius * Math.cos(Math.toRadians(18)));
- list.add(cy - radius * Math.sin(Math.toRadians(18)));
- list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(72)));
- list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(72)));
- list.add(cx + radius * Math.cos(Math.toRadians(90)));
- list.add(cy - radius * Math.sin(Math.toRadians(90)));
- list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(108)));
- list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(108)));
- list.add(cx + radius * Math.cos(Math.toRadians(162)));
- list.add(cy - radius * Math.sin(Math.toRadians(162)));
- list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(180)));
- list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(180)));
- list.add(cx + radius * Math.cos(Math.toRadians(234)));
- list.add(cy - radius * Math.sin(Math.toRadians(234)));
- list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(270)));
- list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(270)));
- list.add(cx + radius * Math.cos(Math.toRadians(306)));
- list.add(cy - radius * Math.sin(Math.toRadians(306)));
- list.add(cx + (.3 * radius) * Math.cos(Math.toRadians(360)));
- list.add(cy - (.3 * radius) * Math.sin(Math.toRadians(360)));
- list.add(cx + radius * Math.cos(Math.toRadians(378)));
- list.add(cy - radius * Math.sin(Math.toRadians(378)));
- p.setFill(Color.WHITE);
- p.setStroke(Color.WHITE);
- this.getChildren().add(p);
- return p;
- }
- @Override
- public void setWidth(double width) {
- super.setWidth(width);
- paint();
- }
- @Override
- public void setHeight(double height) {
- super.setHeight(height);
- paint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement