The following is a pseudo code for generating consecutive points of a circle of radius 1.0, centered at (1.0, 1.0). The code uses the parametric equation of a circle. PI = 3.14159: dt = 0.01: for (t – 0.0: t
Expert Answer
Point.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package points;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import java.util.ArrayList;
public class Point extends Application {
Pane pn = new Pane();
ArrayList<Circle> cir = new ArrayList<>();
@Override
public void start(Stage primaryStage) {
double wt = 600;
double ht = 400;
VBox info = new VBox();
info.setPadding(new Insets(5, 5, 5, 5));
info.setStyle(“-fx-border-color: red”);
Label lbl1 = new Label(“INSTRUCTIONS:”);
Label lbl2 = new Label(“Add: Left Click”);
Label lbl3 = new Label(“Remove: Right Click”);
info.getChildren().addAll(lbl1, lbl2, lbl3);
Pane infPn = new Pane(info);
infPn.setPadding(new Insets(10, 10, 10, 10));
// Pane
pn.getChildren().addAll(infPn);
info.setLayoutX(10);
info.setLayoutY(10);
pn.setOnMouseClicked(e-> {
double n = e.getX();
double q = e.getY();
if (infPn.contains(n, q)) return;
if (e.getButton() == MouseButton.PRIMARY) {
Circle ccl = pointDraw(n,q);
cir.add(ccl);
pn.getChildren().add(ccl);
dispBoundary();
} else if (e.getButton() == MouseButton.SECONDARY) {
rmPnt(n, q);
dispBoundary();
}
});
Scene scene = new Scene(pn, wt, ht);
primaryStage.setScene(scene);
primaryStage.setTitle(“Drawing Board”);
primaryStage.show();
}
private Circle pointDraw(double n, double q) {
Circle ccl = new Circle(n, q, 10, Color.TRANSPARENT);
ccl.setStroke(Color.BLACK);
return ccl;
}
private void dispBoundary() {
rmRec(); // removes old rect
if (cir.size() == 0) return;
// assume first circle is the current bounding limit
Circle above = cir.get(0);
Circle below = cir.get(0);
Circle rt = cir.get(0);
Circle lt = cir.get(0);
// get lowest n,q and get highest n,q
for (Circle ccl : cir) {
if (ccl.getCenterX() < lt.getCenterX()) lt = ccl;
if (ccl.getCenterX() > rt.getCenterX()) rt = ccl;
if (ccl.getCenterY() > below.getCenterY()) below = ccl;
if (ccl.getCenterY() < above.getCenterY()) above = ccl;
}
// all circles have the same radius
double wt = rt.getCenterX() – lt.getCenterX() + above.getRadius() * 2;
double ht = below.getCenterY() – above.getCenterY() + above.getRadius() * 2;
double cntX = (rt.getCenterX() + lt.getCenterX()) / 2;
double cntY = (above.getCenterY() + below.getCenterY()) / 2;
Rectangle rect = new Rectangle(cntX – wt / 2, cntY – ht / 2, wt, ht);
rect.setStroke(Color.BLACK);
rect.setFill(Color.TRANSPARENT);
pn.getChildren().add(rect);
}
private void rmPnt(double n, double q) {
ObservableList<Node> ls = pn.getChildren();
for (int uu = ls.size() – 1; uu >= 0; uu–) {
Node ccl = ls.get(uu);
if (ccl instanceof Circle && ccl.contains(n, q)) {
pn.getChildren().remove(ccl);
cir.remove(ccl);
break;
}
}
}
private void rmRec(){
ObservableList<Node> ls = pn.getChildren();
for (Node ccl : ls) {
if (ccl instanceof Rectangle) {
pn.getChildren().remove(ccl);
break;
}
}
}
public static void main(String[] args) {
Application.launch(args);
}
}
Output: