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 68 69 70 71 72 73 74
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 _kaitentai extends Application { public static void main(String... args) { Application.launch(args); } private static final int VIEW_W = 400, VIEW_H = 300; private GraphicsContext gc; private _transform tf; @Override public void start(Stage stage) throws Exception { BorderPane pane = new BorderPane(); stage.setScene(new Scene(pane)); Canvas view = new Canvas(VIEW_W, VIEW_H); gc = view.getGraphicsContext2D(); tf = new _transform(); tf.angle(-30, 30); tf.position(0, -90, 0); tf.add_angle_listener(stage.getScene(), () -> { draw(); }); pane.setCenter(view); draw(); stage.show(); } private static final int ROUND_N = 90, RYOU_SEN_N = 6; private double[][] glass = { { 100, 180 }, { 55, 140 }, { 10, 100 }, { 10, 60 }, { 10, 20 }, { 50, 10 }, { 80, 4 }, { 80, 0 } }; private void draw() { gc.setTransform(1, 0, 0, 1, 0, 0); gc.clearRect(0, 0, VIEW_W, VIEW_H); gc.setTransform(1, 0, 0, -1, VIEW_W / 2, VIEW_H / 2); for (int i = 0; i < glass.length; i++) draw_toukou_sen(glass[i]); for (int i = 0; i < RYOU_SEN_N; i++) draw_ryou_sen(2 * Math.PI * i / RYOU_SEN_N, glass); } private void draw_toukou_sen(double[] v) { gc.beginPath(); double r = v[0], y = v[1], t; double[] p; for (int i = 0; i < ROUND_N; i++) { t = 2 * Math.PI * i / ROUND_N; p = project(tf.mul(r * Math.sin(t), y, r * Math.cos(t))); if (i == 0) gc.moveTo(p[0], p[1]); gc.lineTo(p[0], p[1]); } gc.closePath(); gc.stroke(); } private void draw_ryou_sen(double t, double[][] v) { gc.beginPath(); double r, y; double[] p; for (int i = 0; i < v.length; i++) { r = v[i][0]; y = v[i][1]; p = project(tf.mul(r * Math.sin(t), y, r * Math.cos(t))); if (i == 0) gc.moveTo(p[0], p[1]); gc.lineTo(p[0], p[1]); } gc.stroke(); } private double[] project(double[] v) { return v; } }