import static java.lang.Math.PI; import static java.lang.Math.cos; import static java.lang.Math.sin; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.stage.Stage; public class N_gon extends Application { public void start(Stage stage) { stage.setTitle("正多角形"); final Canvas canvas = new Canvas(220, 220); GraphicsContext gc = canvas.getGraphicsContext2D(); int np = 7; int sc = 100; int i; double theta1, theta2; for(i = 0; i < np; i++) { // 単位 ラジアン theta1 = PI * 2 * i / np; // 360 * i / n度 theta2 = PI * 2 * (i + 1) / np; // 360 * (i + 1) / n度 gc.strokeLine((int)(sc * (1.1 + cos(theta1))), (int)(sc * (1.1 + sin(theta1))), (int)(sc * (1.1 + cos(theta2))), (int)(sc * (1.1 + sin(theta2)))); } Group root = new Group(); root.getChildren().addAll(canvas); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String... args) { launch(args); } }