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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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.scene.paint.Color; import javafx.stage.Stage; public class _f1_machine 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 int[][] side = {{40, 5}, {40, 13}, {40, 16, 43, 16}, {60, 16}, {70, 16, 75, 6, 85, 6}, {85, 0}}; private int[][] core = {{0, 0}, {0, 3, 25, 5, 35, 5}, {50, 5}, {60, 5, 80, 2, 80, 0}}; private int[][] cockpit = {{31, 0}, {31, 3, 40, 3}, {44, 3}, {46, 3, 46, 0}}; private void draw(GraphicsContext gc) { gc.setTransform(-4, 0, 0, -4, VIEW_W, VIEW_H / 2); gc.setLineWidth(0.25); gc.strokeRect(2, -16, 8, 32); gc.strokeRect(85,-12, 15, 24); for (int i = 0; i < 2; i++) { gc.setFill(Color.BLACK); gc.strokeRoundRect(10, 17, 15, 8, 2, 2); gc.strokeRoundRect(75, 15, 15, 10, 2, 2); gc.setFill(Color.WHITE); draw_path(gc, side); draw_path(gc, core); draw_path(gc, cockpit); gc.transform(1, 0, 0, -1, 0, 0); } } private void draw_path(GraphicsContext gc, int[][] path) { gc.beginPath(); gc.moveTo(path[0][0], path[0][1]); for (int i = 1; i < path.length; i++) { int[] line = path[i]; if (line.length == 2) { gc.lineTo(line[0], line[1]); } else if (line.length == 4) { gc.quadraticCurveTo(line[0], line[1], line[2], line[3]); } else if (line.length == 6) { gc.bezierCurveTo(line[0], line[1], line[2], line[3], line[4], line[5]); } } gc.fill(); gc.stroke(); } }