Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package flag;
- import javafx.collections.ObservableList;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Polygon;
- import javafx.scene.shape.Rectangle;
- public class FlagPane extends Pane {
- private void paint() {
- this.getChildren().clear();
- // Stripes
- for (int i = 0; i < 7; i++) {
- Rectangle stripe = new Rectangle();
- stripe.setX(10);
- stripe.setWidth(getWidth() - 20);
- stripe.setHeight((getHeight() - 20) / 13.0);
- stripe.setY((getHeight() - 20) / 13.0 * (2 * i) + 10);
- stripe.setFill(Color.RED);
- this.getChildren().add(stripe);
- }
- // Blue Box
- Rectangle box = new Rectangle();
- box.setX(10);
- box.setY(10);
- box.setWidth(2 * (getWidth() - 20) / 5);
- box.setHeight(7 * (getHeight() - 21) / 13);
- box.setFill(Color.DARKBLUE);
- this.getChildren().add(box);
- // Stars
- double heightChange = 10;
- double heightChange2 = 10;
- double widthChange = 10;
- for (int i = 0; i < 5; i++){
- for (int j = 0; j < 6; j++)
- genStar(heightChange, widthChange + (j * (getWidth()*0.0625)));
- heightChange = heightChange + (getHeight() * 0.0950);
- }
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 5; j++)
- genStar2(heightChange2, widthChange + (j * (getWidth()*0.0625)));
- heightChange2 = heightChange2 + (getHeight() * 0.0950);
- }
- }
- private void genStar(Double heightChange, Double widthChange){
- double radius = (getHeight() - 20) * 0.025;
- double radius2 = radius / 2.8;
- Polygon star = new Polygon();
- ObservableList<Double> list = star.getPoints();
- for (int j = 0; j < 9; j ++){
- if (j % 2 == 0){
- list.add(((getWidth() - 20) * 0.0332) + radius * Math.cos(2*j*Math.toRadians(36)) + widthChange);
- list.add(((getHeight() - 20) * 0.054) - radius * Math.sin(2*j*Math.toRadians(36)) + heightChange);
- }else{
- list.add(((getWidth() - 20) * 0.0332) + radius2 * Math.cos(2*j*Math.toRadians(36)) + widthChange);
- list.add(((getHeight() - 20) * 0.054) - radius2 * Math.sin(2*j*Math.toRadians(36)) + heightChange);
- }
- }
- star.setRotate(-18);
- star.setFill(Color.WHITE);
- this.getChildren().add(star);
- }
- private void genStar2(Double heightChange, Double widthChange){
- double radius = (getHeight() - 20) * 0.025;
- double radius2 = radius / 2.8;
- Polygon star = new Polygon();
- ObservableList<Double> list = star.getPoints();
- for (int j = 0; j < 9; j ++){
- if (j % 2 == 0){
- list.add(((getWidth() - 20) * 0.0664) + radius * Math.cos(2*j*Math.toRadians(36)) + widthChange);
- list.add(((getHeight() - 20) * 0.108) - radius * Math.sin(2*j*Math.toRadians(36)) + heightChange);
- }else{
- list.add(((getWidth() - 20) * 0.0664) + radius2 * Math.cos(2*j*Math.toRadians(36)) + widthChange);
- list.add(((getHeight() - 20) * 0.108) - radius2 * Math.sin(2*j*Math.toRadians(36)) + heightChange);
- }
- }
- star.setRotate(-18);
- star.setFill(Color.WHITE);
- this.getChildren().add(star);
- }
- @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