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
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 _symmetry 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() {
double w = 70, h = w * Math.sqrt(3) / 2, t = Math.PI * 2 / 3;
double sign;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 13; j++) {
sign = (i % 2 == j % 2) ? 1 : -1;
gc.setTransform(sign, 0, 0, sign,
(j - 6) * w / 2 + VIEW_W / 2,
(i - 2) * h + sign * h / 6 + VIEW_H / 2);
for (int k = 0; k < 3; k++) {
draw_path();
gc.transform(Math.cos(t), Math.sin(t),
-Math.sin(t), Math.cos(t), 0, 0);
}
}
}
}
private void draw_path() {
double[][] path = {
{ 35, 20 }, { 19, 20 }, { 10, 5 },
{ 3, 5 }, { 0, 0 }, { -3, 5 },
{ -10, 5 }, { -19, 20 }, { -35, 20 }};
gc.beginPath();
gc.moveTo(path[0][0], path[0][1]);
for (int i = 1; i < path.length; i++)
gc.lineTo(path[i][0], path[i][1]);
gc.stroke();
}
}