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
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 _lissajous_kyokusen extends Application {
public static void main(String... args) {
Application.launch(args);
}
private static final int VIEW_W = 400, VIEW_H = 300;
private GraphicsContext gc;
@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();
pane.setCenter(view);
draw();
stage.show();
}
private void draw() {
gc.setTransform(1, 0, 0, 1, VIEW_W / 2, VIEW_H / 2);
double x, y, t;
gc.setStroke(Color.GRAY);
for (int i = 0; i < 11; i++) {
x = y = 30 * i - 150;
draw_line(-150, y, 150, y);
draw_line(x, -150, x, 150);
}
gc.setStroke(Color.BLACK);
gc.beginPath();
for (int deg = 0; deg <= 1080; deg += 2) {
t = deg * Math.PI / 180;
x = 150 * Math.sin(2 * t);
y = 150 * Math.sin(3 * t);
if (deg == 0) gc.moveTo(x, y);
else gc.lineTo(x, y);
}
gc.stroke();
}
private void draw_line(double x1, double y1, double x2, double y2) {
gc.beginPath();
gc.moveTo(x1, y1);
gc.lineTo(x2, y2);
gc.stroke();
}
}