With DisplacementMap effect, we can move pixel in x or y.
Here motion is based on absolute function on the y-axis There is no x-displacement.
package ex63;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.effect.DisplacementMap;
import javafx.scene.effect.FloatMap;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class Ex63 extends Application {
@Override
public void start(Stage stage) {
Group root = new Group();
FloatMap map = new FloatMap(250, 100);
for (int i = 0; i < map.getWidth(); i++) {
double value = -Math.abs(.002*(i-125));
for (int j = 0; j < map.getHeight(); j++)
map.setSamples(i, j, 0f, (float)value);
}
DisplacementMap displacementMap = new DisplacementMap(map);
Label label = new Label("Displacement");
label.setFont(Font.font("Georgia", 50));
label.setPrefHeight(100);
label.setLayoutX(55); label.setLayoutY(30);
label.setEffect(displacementMap);
root.getChildren().add(label);
Scene scene = new Scene(root, 450, 200, Color.LIGHTYELLOW);
stage.setTitle("Example 63. DisplacementMap");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
This is the output:
No comments:
Post a Comment