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
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 _insen_shori 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.add_angle_listener(stage.getScene(), () -> { draw(); });
pane.setCenter(view);
draw();
stage.show();
}
private double[] min = new double[VIEW_W], max = new double[VIEW_W];
private void draw() {
for (int i = 0; i < VIEW_W; i++) {
min[i] = VIEW_H; max[i] = -VIEW_H;
}
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 (double z = -150; z <= 150; z += 10) {
for (double x = -150; x <= 150; x++) {
double t = Math.sqrt(x * x + z * z) * Math.PI / 180;
double y = 20 * (Math.cos(t) + Math.cos(3 * t));
double[] p = project(tf.mul(x, y, z));
int i = (int)(p[0] + VIEW_W / 2 + 0.5);
if (i < 0 || i >= VIEW_W)
continue;
double px = p[0], py = p[1];
if (py < min[i] || py > max[i])
gc.fillRect(px, py, 1, 1);
min[i] = Math.min(py, min[i]);
max[i] = Math.max(py, max[i]);
}
}
}
private double[] project(double[] v) {
return v;
}
}