use of org.fxyz.shapes.composites.Histogram in project FXyzLib by Birdasaur.
the class HistogramTest method start.
@Override
public void start(Stage primaryStage) throws Exception {
Group sceneRoot = new Group();
Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateZ(-1000);
scene.setCamera(camera);
histogram = new Histogram(1000, 1, true);
sceneRoot.getChildren().addAll(histogram);
int size = 30;
float[][] arrayY = new float[2 * size][2 * size];
for (int i = -size; i < size; i++) {
for (int j = -size; j < size; j++) {
// Transcedental Gradient
double xterm = (Math.cos(Math.PI * i / size) * Math.cos(Math.PI * i / size));
double yterm = (Math.cos(Math.PI * j / size) * Math.cos(Math.PI * j / size));
arrayY[i + size][j + size] = (float) (10 * ((xterm + yterm) * (xterm + yterm)));
}
}
histogram.setHeightData(arrayY, 1, 4, Color.SKYBLUE, false, true);
scene.setOnKeyPressed(event -> {
double change = 10.0;
// Add shift modifier to simulate "Running Speed"
if (event.isShiftDown()) {
change = 50.0;
}
// What key did the user press?
KeyCode keycode = event.getCode();
// Step 2c: Add Zoom controls
if (keycode == KeyCode.W) {
camera.setTranslateZ(camera.getTranslateZ() + change);
}
if (keycode == KeyCode.S) {
camera.setTranslateZ(camera.getTranslateZ() - change);
}
// Step 2d: Add Strafe controls
if (keycode == KeyCode.A) {
camera.setTranslateX(camera.getTranslateX() - change);
}
if (keycode == KeyCode.D) {
camera.setTranslateX(camera.getTranslateX() + change);
}
});
// Add a Mouse Handler for Rotations
Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
histogram.getTransforms().addAll(xRotate, yRotate);
// Use Binding so your rotation doesn't have to be recreated
xRotate.angleProperty().bind(angleX);
yRotate.angleProperty().bind(angleY);
zRotate.angleProperty().bind(angleZ);
// Start Tracking mouse movements only when a button is pressed
scene.setOnMousePressed(event -> {
scenex = event.getSceneX();
sceney = event.getSceneY();
fixedXAngle = angleX.get();
fixedYAngle = angleY.get();
if (event.isMiddleButtonDown()) {
scenez = event.getSceneX();
fixedZAngle = angleZ.get();
}
});
// Angle calculation will only change when the button has been pressed
scene.setOnMouseDragged(event -> {
if (event.isMiddleButtonDown()) {
angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
} else {
angleX.set(fixedXAngle - (scenex - event.getSceneY()));
}
angleY.set(fixedYAngle + sceney - event.getSceneX());
});
primaryStage.setTitle("F(X)yz HistogramTest");
primaryStage.setScene(scene);
primaryStage.show();
}