1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package sample; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class _spade extends Application { public static void main(String... args) { Application.launch(args); } private static final int VIEW_W = 400, VIEW_H = 300; @Override public void start(Stage stage) throws Exception { BorderPane pane = new BorderPane(); Scene scene = new Scene(pane); stage.setScene(scene); Canvas view = new Canvas(VIEW_W, VIEW_H); pane.setCenter(view); draw(view.getGraphicsContext2D()); stage.show(); } private double[][] p = { {-10, 60}, {-200, 240}, {20, 240}, {-80, 300}, {80, 300}, {-20, 240}, {200, 240}, {10, 60}, }; private void draw(GraphicsContext gc) { gc.setTransform(1, 0, 0, 1, VIEW_W / 2, 0); double x1, y1, x2, y2; int n = p.length; gc.beginPath(); gc.moveTo(0, 0); for (int i = 0; i < n; i++) { x1 = p[i][0]; y1 = p[i][1]; if (i == n - 1) { x2 = 0; y2 = 0; } else { x2 = (p[i][0] + p[i + 1][0]) / 2; y2 = (p[i][1] + p[i + 1][1]) / 2; } gc.quadraticCurveTo(x1, y1, x2, y2); } gc.fill(); } }