Java

Most recent work in Java.

Return to home page

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;

/**
 *  This program creates a slice of pizza using Java FX.
 *  @author Samantha Kuney 
 *  11/28/2017
 */

public class Prizza extends Application {
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Pizza"); 	// sets the stage title
		primaryStage.setScene(createScene()); // place scene on stage
		primaryStage.show();
	}

	private Scene createScene() {
		Group master = new Group();
		Group group = buildPizza(100, 100, 2, Color.BISQUE); // big soup pizza
		Group group1 = buildPizza(550, 200, 1, Color.CHARTREUSE); // moldyPizza
		Group group2 = buildPizza(800, 200); // regular pizza

		master.getChildren().addAll(group, group1, group2);
		Scene scene = new Scene(master, 1200, 800); // sets dimensions of scene

		return scene;
	}

	private Group buildPizza() { // creates slice in corner of pane
		return buildPizza(0, 0);
	}

	private Group buildPizza(int x, int y) {
		Polygon triangle = new Polygon(); // creates slice at specific point
		triangle.getPoints().addAll(new Double[] { x + 0.0, y + 0.0, x + 200.0, y + 100.0, x + 100.0, y + 200.0 });
		triangle.setStroke(Color.ORANGE);
		triangle.setFill(Color.YELLOW);

		Group build = new Group();
		build.getChildren().add(triangle); // adds slice to the scene
		build.getChildren().add(getPepz(x + 110, y + 140, 15, Color.RED));// adds pieces of pepperoni
		build.getChildren().add(getPepz(x + 150, y + 100, 15, Color.RED));
		build.getChildren().add(getPepz(x + 80, y + 85, 15, Color.RED));
		build.getChildren().add(getPepz(x + 45, y + 45, 15, Color.RED));

		return build;

	}

	private Group buildPizza(int x, int y, int r) { // allows scale to be changed
		Polygon triangle = new Polygon(); // creates slice at specific point
		triangle.getPoints()
				.addAll(new Double[] { x + 0.0, y + 0.0, x + 200.0 * r, y + 100.0 * r, x + 100.0 * r, y + 200.0 * r });
		triangle.setStroke(Color.ORANGE);
		triangle.setFill(Color.YELLOW);

		Group build = new Group();
		build.getChildren().add(triangle); // adds slice to the scene
		build.getChildren().add(getPepz(x + 110, y + 140, 15, Color.RED));// adds pieces of pepperoni
		build.getChildren().add(getPepz(x + 150, y + 100, 15, Color.RED));
		build.getChildren().add(getPepz(x + 80, y + 85, 15, Color.RED));
		build.getChildren().add(getPepz(x + 45, y + 45, 15, Color.RED));

		return build;

	}

	private Group buildPizza(int x, int y, int r, Color pizzaMoldColor) { // allows color of pepperoni to be modified
		Polygon triangle = new Polygon(); // creates slice at specific point
		triangle.getPoints()
				.addAll(new Double[] { x + 0.0, y + 0.0, x + 200.0 * r, y + 100.0 * r, x + 100.0 * r, y + 200.0 * r });
		triangle.setStroke(Color.ORANGE);
		triangle.setFill(Color.YELLOW);

		Group build = new Group();
		build.getChildren().add(triangle); // adds slice to the scene
		build.getChildren().add(getPepz(x + 110, y + 140, 15, pizzaMoldColor));// adds pieces of pepperoni
		build.getChildren().add(getPepz(x + 150, y + 100, 15, pizzaMoldColor));
		build.getChildren().add(getPepz(x + 80, y + 85, 15, pizzaMoldColor));
		build.getChildren().add(getPepz(x + 45, y + 45, 15, pizzaMoldColor));

		return build;

	}

	private Circle getPepz(int x, int y, int r, Color c) { // creates pepperoni
		Circle pepperoni = new Circle();
		pepperoni.setCenterX(x);
		pepperoni.setCenterY(y);
		pepperoni.setRadius(r);
		pepperoni.setStroke(c.darker());
		pepperoni.setFill(c);

		return pepperoni;
	}

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