Java Code Examples for javafx.scene.shape.Circle#getCenterX()
The following examples show how to use
javafx.scene.shape.Circle#getCenterX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatchBall.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private void catchEnemy(Circle hero, List<Circle> apples, Pane canvas) { double heroX = hero.getTranslateX() + hero.getCenterX(); double heroY = hero.getTranslateY() + hero.getCenterY(); for (Circle apple : apples) { double enemyX = apple.getLayoutX() - apple.getRadius() / 2; double enemyY = apple.getLayoutY() - apple.getRadius() / 2; if (heroX + hero.getRadius() >= enemyX && heroX <= enemyX && heroY + hero.getRadius() >= enemyY && heroY <= enemyY) { canvas.getChildren().remove(apple); break; } } }
Example 2
Source File: Exercise_14_22.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create two circles Circle c1 = new Circle(20 + Math.random() * 201, 20 + Math.random() * 201, 15); c1.setFill(Color.WHITE); c1.setStroke(Color.BLACK); Circle c2 = new Circle(20 + Math.random() * 201, 20 + Math.random() * 201, 15); c2.setFill(Color.WHITE); c2.setStroke(Color.BLACK); // Create a line Line line = new Line(c1.getCenterX(), c1.getCenterY(), c2.getCenterX(), c2.getCenterY()); // Add nodes to pane pane.getChildren().addAll(line, c1, c2, new Text(c1.getCenterX(), c1.getCenterY(), "1"), new Text(c2.getCenterX(), c2.getCenterY(), "2")); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("Exercise_14_22"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example 3
Source File: Exercise_14_11.java From Intro-to-Java-Programming with MIT License | 5 votes |
/** Return a Polygon of specified properties */ private Polygon getPolygon(Circle c) { double length = c.getRadius() / 4; Polygon p = new Polygon(c.getCenterX(), c.getCenterY() - length, c.getCenterX() - length, c.getCenterY() + length, c.getCenterX() + length, c.getCenterY() + length); p.setFill(Color.WHITE); p.setStroke(Color.BLACK); return p; }
Example 4
Source File: Exercise_14_21.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create two circles Circle circle1 = new Circle(Math.random() * 201, Math.random() * 201, 15); Circle circle2 = new Circle(Math.random() * 201, Math.random() * 201, 15); // Create a line Line line = new Line(circle1.getCenterX(), circle1.getCenterY(), circle2.getCenterX(), circle2.getCenterY()); // Calculate distane between the two centers of the circles double distance = Math.sqrt(Math.pow(line.getEndX() - line.getStartX(), 2) + Math.pow(line.getEndY() - line.getStartY(), 2)); // Create a text double x = (line.getStartX() + line.getEndX()) / 2; double y = (line.getStartY() + line.getEndY()) / 2; Text text = new Text(x, y, String.valueOf(distance)); // Add nodes to pane pane.getChildren().addAll(circle1, circle2, line, text); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("Exercise_14_21"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example 5
Source File: ShapeConverter.java From Enzo with Apache License 2.0 | 5 votes |
public static String convertCircle(final Circle CIRCLE) { final StringBuilder fxPath = new StringBuilder(); final double CENTER_X = CIRCLE.getCenterX() == 0 ? CIRCLE.getRadius() : CIRCLE.getCenterX(); final double CENTER_Y = CIRCLE.getCenterY() == 0 ? CIRCLE.getRadius() : CIRCLE.getCenterY(); final double RADIUS = CIRCLE.getRadius(); final double CONTROL_DISTANCE = RADIUS * KAPPA; // Move to first point fxPath.append("M ").append(CENTER_X).append(" ").append(CENTER_Y - RADIUS).append(" "); // 1. quadrant fxPath.append("C ").append(CENTER_X + CONTROL_DISTANCE).append(" ").append(CENTER_Y - RADIUS).append(" ") .append(CENTER_X + RADIUS).append(" ").append(CENTER_Y - CONTROL_DISTANCE).append(" ") .append(CENTER_X + RADIUS).append(" ").append(CENTER_Y).append(" "); // 2. quadrant fxPath.append("C ").append(CENTER_X + RADIUS).append(" ").append(CENTER_Y + CONTROL_DISTANCE).append(" ") .append(CENTER_X + CONTROL_DISTANCE).append(" ").append(CENTER_Y + RADIUS).append(" ") .append(CENTER_X).append(" ").append(CENTER_Y + RADIUS).append(" "); // 3. quadrant fxPath.append("C ").append(CENTER_X - CONTROL_DISTANCE).append(" ").append(CENTER_Y + RADIUS).append(" ") .append(CENTER_X - RADIUS).append(" ").append(CENTER_Y + CONTROL_DISTANCE).append(" ") .append(CENTER_X - RADIUS).append(" ").append(CENTER_Y).append(" "); // 4. quadrant fxPath.append("C ").append(CENTER_X - RADIUS).append(" ").append(CENTER_Y - CONTROL_DISTANCE).append(" ") .append(CENTER_X - CONTROL_DISTANCE).append(" ").append(CENTER_Y - RADIUS).append(" ") .append(CENTER_X).append(" ").append(CENTER_Y - RADIUS).append(" "); // Close path fxPath.append("Z"); return fxPath.toString(); }
Example 6
Source File: NodePart.java From gef with Eclipse Public License 2.0 | 4 votes |
private Node edge(Circle n, Circle m) { Line line = new Line(n.getCenterX(), n.getCenterY(), m.getCenterX(), m.getCenterY()); line.setStroke(Color.BLACK); return line; }
Example 7
Source File: Exercise_15_16.java From Intro-to-Java-Programming with MIT License | 4 votes |
private Text getText(Circle circle1, Circle circle2) { return new Text((circle1.getCenterX() + circle2.getCenterX()) / 2, (circle1.getCenterY() + circle2.getCenterY()) / 2, distance(circle1, circle2)); }
Example 8
Source File: Exercise_15_16.java From Intro-to-Java-Programming with MIT License | 4 votes |
private Line getLine(Circle circle1, Circle circle2) { return new Line(circle1.getCenterX(), circle1.getCenterY(), circle2.getCenterX(), circle2.getCenterY()); }
Example 9
Source File: Shape2Geometry.java From gef with Eclipse Public License 2.0 | 3 votes |
/** * Converts the given JavaFX {@link Circle} to a * {@link org.eclipse.gef.geometry.planar.Ellipse}. * * @param circle * The JavaFX {@link Circle} to convert. * @return The newly created * {@link org.eclipse.gef.geometry.planar.Ellipse} that describes * the given {@link Circle}. */ public static org.eclipse.gef.geometry.planar.Ellipse toEllipse( Circle circle) { return new org.eclipse.gef.geometry.planar.Ellipse( circle.getCenterX() - circle.getRadius(), circle.getCenterY() - circle.getRadius(), circle.getRadius() + circle.getRadius(), circle.getRadius() + circle.getRadius()); }