package edu.bloomu.ch3b;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;

/**
 * Draws a six-pointed golden star.
 * 
 * @author Drue Coles
 */
public class StarryNight extends Application {

    @Override
    public void start(Stage stage) {
        Pane root = new Pane();
        final int n = 250; // width and height of scene
        Scene scene = new Scene(root, n, n, Color.BLACK);

        // The star will be rendered as two triangles. 
        final int centerX = n / 2; // x-coordinate of center of stage
        final int centerY = n / 2; // y-coordinate of center of stage
        final int radius = 100; // radius of circle that circumscribes each triangle
        
        // Vertices of first triangle are 90°, 210°, and 330° about the center.
        double x1 = centerX + radius * Math.cos(Math.toRadians(90)); 
        double y1 = centerY - radius * Math.sin(Math.toRadians(90));
        double x2 = centerX + radius * Math.cos(Math.toRadians(210)); 
        double y2 = centerY - radius * Math.sin(Math.toRadians(210));
        double x3 = centerX + radius * Math.cos(Math.toRadians(330));
        double y3 = centerY - radius * Math.sin(Math.toRadians(330));
        Polygon triangle1 = new Polygon(x1, y1, x2, y2, x3, y3);
       
        // The second triangle is initialized to the same state as the first and then 
        // rotated and shifted so that the two triangles form a six-pointed star.
        Polygon triangle2 = new Polygon(x1, y1, x2, y2, x3, y3);
        triangle2.setRotate(180);
        triangle2.setTranslateY(radius / 2);        
        
        triangle1.setFill(Color.DARKGOLDENROD);
        triangle2.setFill(Color.DARKGOLDENROD);    
        
        root.getChildren().addAll(triangle1, triangle2);
        root.setRotate(45);
      
        stage.setTitle("Starry Night");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}