DisplacementMap (JavaFX 27)
Description: declaration: module: javafx.graphics, package: javafx.scene.effect, class: DisplacementMap

# Class DisplacementMap

java.lang.Object
javafx.scene.effect.Effect
javafx.scene.effect.DisplacementMap

public class DisplacementMap extends Effect
An effect that shifts each pixel by a distance specified by the first two bands of of the specified `FloatMap`. For each pixel in the output, the corresponding data from the `mapData` is retrieved, scaled and offset by the `scale` and `offset` attributes, scaled again by the size of the source input image and used as an offset from the destination pixel to retrieve the pixel data from the source input.

`dst[x, y] = src[(x, y) + (offset + scale * map[x, y]) * (srcw, srch)]`

A value of `(0.0, 0.0)` would specify no offset for the pixel data whereas a value of `(0.5, 0.5)` would specify an offset of half of the source image size.

Note that the mapping is the offset from a destination pixel to the source pixel location from which it is sampled which means that filling the map with all values of `0.5` would displace the image by half of its size towards the upper left since each destination pixel would contain the data that comes from the source pixel below and to the right of it.

Also note that this effect does not adjust the coordinates of input events or any methods that measure containment on a `Node`. The results of mouse picking and the containment methods are undefined when a `Node` has a `DisplacementMap` effect in place.

Example:

     int width = 220;
    int height = 100;

    FloatMap floatMap = new FloatMap();
    floatMap.setWidth(width);
    floatMap.setHeight(height);

    for (int i = 0; i < width; i++) {
        double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0;
        for (int j = 0; j < height; j++) {
            floatMap.setSamples(i, j, 0.0f, (float) v);
        }
    }

    DisplacementMap displacementMap = new DisplacementMap();
    displacementMap.setMapData(floatMap);

    Text text = new Text();
    text.setX(40.0);
    text.setY(80.0);
    text.setText("Wavy Text");
    text.setFill(Color.web("0x3b596d"));
    text.setFont(Font.font(null, FontWeight.BOLD, 50));
    text.setEffect(displacementMap);

The code above produces the following:

Since:
  JavaFX 2.0

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final ObjectProperty<Effect>`
  `input`
  The input for this `Effect`.
  `final ObjectProperty<FloatMap>`
  `mapData`
  The map data for this `Effect`.
  `final DoubleProperty`
  `offsetX`
  The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.
  `final DoubleProperty`
  `offsetY`
  The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.
  `final DoubleProperty`
  `scaleX`
  The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.
  `final DoubleProperty`
  `scaleY`
  The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.
  `final BooleanProperty`
  `wrap`
  Defines whether values taken from outside the edges of the map "wrap around" or not.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DisplacementMap()`
  Creates a new instance of DisplacementMap with default parameters.
  `DisplacementMap(FloatMap mapData)`
  Creates a new instance of DisplacementMap with the specified mapData.
  `DisplacementMap(FloatMap mapData, double offsetX, double offsetY, double scaleX, double scaleY)`
  Creates a new instance of DisplacementMap with the specified mapData, offsetX, offsetY, scaleX, and scaleY.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final Effect`
  `getInput()`
  Gets the value of the `input` property.
  `final FloatMap`
  `getMapData()`
  Gets the value of the `mapData` property.
  `final double`
  `getOffsetX()`
  Gets the value of the `offsetX` property.
  `final double`
  `getOffsetY()`
  Gets the value of the `offsetY` property.
  `final double`
  `getScaleX()`
  Gets the value of the `scaleX` property.
  `final double`
  `getScaleY()`
  Gets the value of the `scaleY` property.
  `final ObjectProperty<Effect>`
  `inputProperty()`
  The input for this `Effect`.
  `final boolean`
  `isWrap()`
  Gets the value of the `wrap` property.
  `final ObjectProperty<FloatMap>`
  `mapDataProperty()`
  The map data for this `Effect`.
  `final DoubleProperty`
  `offsetXProperty()`
  The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.
  `final DoubleProperty`
  `offsetYProperty()`
  The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.
  `final DoubleProperty`
  `scaleXProperty()`
  The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.
  `final DoubleProperty`
  `scaleYProperty()`
  The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.
  `final void`
  `setInput(Effect value)`
  Sets the value of the `input` property.
  `final void`
  `setMapData(FloatMap value)`
  Sets the value of the `mapData` property.
  `final void`
  `setOffsetX(double value)`
  Sets the value of the `offsetX` property.
  `final void`
  `setOffsetY(double value)`
  Sets the value of the `offsetY` property.
  `final void`
  `setScaleX(double value)`
  Sets the value of the `scaleX` property.
  `final void`
  `setScaleY(double value)`
  Sets the value of the `scaleY` property.
  `final void`
  `setWrap(boolean value)`
  Sets the value of the `wrap` property.
  `final BooleanProperty`
  `wrapProperty()`
  Defines whether values taken from outside the edges of the map "wrap around" or not.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Property Details

  - ### input

    public final ObjectProperty<Effect> inputProperty
    The input for this `Effect`. If set to `null`, or left unspecified, a graphical image of the `Node` to which the `Effect` is attached will be used as the input.
    Default value:
      null
    See Also:
      - `getInput()`
      - `setInput(Effect)`
      - `inputProperty()`

  - ### mapData

    public final ObjectProperty<FloatMap> mapDataProperty
    The map data for this `Effect`.
    Default value:
      an empty map
    See Also:
      - `getMapData()`
      - `setMapData(FloatMap)`
      - `mapDataProperty()`

  - ### scaleX

    public final DoubleProperty scaleXProperty
    The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.

              Min: n/a
              Max: n/a
          Default: 1.0
         Identity: 1.0

    Default value:
      1.0
    See Also:
      - `getScaleX()`
      - `setScaleX(double)`
      - `scaleXProperty()`

  - ### scaleY

    public final DoubleProperty scaleYProperty
    The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.

              Min: n/a
              Max: n/a
          Default: 1.0
         Identity: 1.0

    Default value:
      1.0
    See Also:
      - `getScaleY()`
      - `setScaleY(double)`
      - `scaleYProperty()`

  - ### offsetX

    public final DoubleProperty offsetXProperty
    The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.

              Min: n/a
              Max: n/a
          Default: 0.0
         Identity: 0.0

    Default value:
      0.0
    See Also:
      - `getOffsetX()`
      - `setOffsetX(double)`
      - `offsetXProperty()`

  - ### offsetY

    public final DoubleProperty offsetYProperty
    The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.

              Min: n/a
              Max: n/a
          Default: 0.0
         Identity: 0.0

    Default value:
      0.0
    See Also:
      - `getOffsetY()`
      - `setOffsetY(double)`
      - `offsetYProperty()`

  - ### wrap

    public final BooleanProperty wrapProperty
    Defines whether values taken from outside the edges of the map "wrap around" or not.

              Min:  n/a
              Max:  n/a
          Default: false
         Identity:  n/a

    Default value:
      false
    See Also:
      - `isWrap()`
      - `setWrap(boolean)`
      - `wrapProperty()`

- ## Constructor Details

  - ### DisplacementMap

    public DisplacementMap()
    Creates a new instance of DisplacementMap with default parameters.

  - ### DisplacementMap

    public DisplacementMap(FloatMap mapData)
    Creates a new instance of DisplacementMap with the specified mapData.
    Parameters:
      `mapData` - the map data for this displacement map effect
    Since:
      JavaFX 2.1

  - ### DisplacementMap

    public DisplacementMap(FloatMap mapData, double offsetX, double offsetY, double scaleX, double scaleY)
    Creates a new instance of DisplacementMap with the specified mapData, offsetX, offsetY, scaleX, and scaleY.
    Parameters:
      `mapData` - the map data for this displacement map effect
      `offsetX` - the offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled
      `offsetY` - the offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled
      `scaleX` - the scale factor by which all x coordinate offset values in the `FloatMap` are multiplied
      `scaleY` - the scale factor by which all y coordinate offset values in the `FloatMap` are multiplied
    Since:
      JavaFX 2.1

- ## Method Details

  - ### setInput

    public final void setInput(Effect value)
    Sets the value of the `input` property.
    Property description:
      The input for this `Effect`. If set to `null`, or left unspecified, a graphical image of the `Node` to which the `Effect` is attached will be used as the input.
    Default value:
      null
    Parameters:
      `value` - the value for the `input` property
    See Also:
      - `getInput()`
      - `inputProperty()`

  - ### getInput

    public final Effect getInput()
    Gets the value of the `input` property.
    Property description:
      The input for this `Effect`. If set to `null`, or left unspecified, a graphical image of the `Node` to which the `Effect` is attached will be used as the input.
    Default value:
      null
    Returns:
      the value of the `input` property
    See Also:
      - `setInput(Effect)`
      - `inputProperty()`

  - ### inputProperty

    public final ObjectProperty<Effect> inputProperty()
    The input for this `Effect`. If set to `null`, or left unspecified, a graphical image of the `Node` to which the `Effect` is attached will be used as the input.
    Default value:
      null
    Returns:
      the `input` property
    See Also:
      - `getInput()`
      - `setInput(Effect)`

  - ### setMapData

    public final void setMapData(FloatMap value)
    Sets the value of the `mapData` property.
    Property description:
      The map data for this `Effect`.
    Default value:
      an empty map
    Parameters:
      `value` - the value for the `mapData` property
    See Also:
      - `getMapData()`
      - `mapDataProperty()`

  - ### getMapData

    public final FloatMap getMapData()
    Gets the value of the `mapData` property.
    Property description:
      The map data for this `Effect`.
    Default value:
      an empty map
    Returns:
      the value of the `mapData` property
    See Also:
      - `setMapData(FloatMap)`
      - `mapDataProperty()`

  - ### mapDataProperty

    public final ObjectProperty<FloatMap> mapDataProperty()
    The map data for this `Effect`.
    Default value:
      an empty map
    Returns:
      the `mapData` property
    See Also:
      - `getMapData()`
      - `setMapData(FloatMap)`

  - ### setScaleX

    public final void setScaleX(double value)
    Sets the value of the `scaleX` property.
    Property description:
      The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.

                Min: n/a
                Max: n/a
            Default: 1.0
           Identity: 1.0

    Default value:
      1.0
    Parameters:
      `value` - the value for the `scaleX` property
    See Also:
      - `getScaleX()`
      - `scaleXProperty()`

  - ### getScaleX

    public final double getScaleX()
    Gets the value of the `scaleX` property.
    Property description:
      The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.

                Min: n/a
                Max: n/a
            Default: 1.0
           Identity: 1.0

    Default value:
      1.0
    Returns:
      the value of the `scaleX` property
    See Also:
      - `setScaleX(double)`
      - `scaleXProperty()`

  - ### scaleXProperty

    public final DoubleProperty scaleXProperty()
    The scale factor by which all x coordinate offset values in the `FloatMap` are multiplied.

              Min: n/a
              Max: n/a
          Default: 1.0
         Identity: 1.0

    Default value:
      1.0
    Returns:
      the `scaleX` property
    See Also:
      - `getScaleX()`
      - `setScaleX(double)`

  - ### setScaleY

    public final void setScaleY(double value)
    Sets the value of the `scaleY` property.
    Property description:
      The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.

                Min: n/a
                Max: n/a
            Default: 1.0
           Identity: 1.0

    Default value:
      1.0
    Parameters:
      `value` - the value for the `scaleY` property
    See Also:
      - `getScaleY()`
      - `scaleYProperty()`

  - ### getScaleY

    public final double getScaleY()
    Gets the value of the `scaleY` property.
    Property description:
      The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.

                Min: n/a
                Max: n/a
            Default: 1.0
           Identity: 1.0

    Default value:
      1.0
    Returns:
      the value of the `scaleY` property
    See Also:
      - `setScaleY(double)`
      - `scaleYProperty()`

  - ### scaleYProperty

    public final DoubleProperty scaleYProperty()
    The scale factor by which all y coordinate offset values in the `FloatMap` are multiplied.

              Min: n/a
              Max: n/a
          Default: 1.0
         Identity: 1.0

    Default value:
      1.0
    Returns:
      the `scaleY` property
    See Also:
      - `getScaleY()`
      - `setScaleY(double)`

  - ### setOffsetX

    public final void setOffsetX(double value)
    Sets the value of the `offsetX` property.
    Property description:
      The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.

                Min: n/a
                Max: n/a
            Default: 0.0
           Identity: 0.0

    Default value:
      0.0
    Parameters:
      `value` - the value for the `offsetX` property
    See Also:
      - `getOffsetX()`
      - `offsetXProperty()`

  - ### getOffsetX

    public final double getOffsetX()
    Gets the value of the `offsetX` property.
    Property description:
      The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.

                Min: n/a
                Max: n/a
            Default: 0.0
           Identity: 0.0

    Default value:
      0.0
    Returns:
      the value of the `offsetX` property
    See Also:
      - `setOffsetX(double)`
      - `offsetXProperty()`

  - ### offsetXProperty

    public final DoubleProperty offsetXProperty()
    The offset by which all x coordinate offset values in the `FloatMap` are displaced after they are scaled.

              Min: n/a
              Max: n/a
          Default: 0.0
         Identity: 0.0

    Default value:
      0.0
    Returns:
      the `offsetX` property
    See Also:
      - `getOffsetX()`
      - `setOffsetX(double)`

  - ### setOffsetY

    public final void setOffsetY(double value)
    Sets the value of the `offsetY` property.
    Property description:
      The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.

                Min: n/a
                Max: n/a
            Default: 0.0
           Identity: 0.0

    Default value:
      0.0
    Parameters:
      `value` - the value for the `offsetY` property
    See Also:
      - `getOffsetY()`
      - `offsetYProperty()`

  - ### getOffsetY

    public final double getOffsetY()
    Gets the value of the `offsetY` property.
    Property description:
      The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.

                Min: n/a
                Max: n/a
            Default: 0.0
           Identity: 0.0

    Default value:
      0.0
    Returns:
      the value of the `offsetY` property
    See Also:
      - `setOffsetY(double)`
      - `offsetYProperty()`

  - ### offsetYProperty

    public final DoubleProperty offsetYProperty()
    The offset by which all y coordinate offset values in the `FloatMap` are displaced after they are scaled.

              Min: n/a
              Max: n/a
          Default: 0.0
         Identity: 0.0

    Default value:
      0.0
    Returns:
      the `offsetY` property
    See Also:
      - `getOffsetY()`
      - `setOffsetY(double)`

  - ### setWrap

    public final void setWrap(boolean value)
    Sets the value of the `wrap` property.
    Property description:
      Defines whether values taken from outside the edges of the map "wrap around" or not.

                Min:  n/a
                Max:  n/a
            Default: false
           Identity:  n/a

    Default value:
      false
    Parameters:
      `value` - the value for the `wrap` property
    See Also:
      - `isWrap()`
      - `wrapProperty()`

  - ### isWrap

    public final boolean isWrap()
    Gets the value of the `wrap` property.
    Property description:
      Defines whether values taken from outside the edges of the map "wrap around" or not.

                Min:  n/a
                Max:  n/a
            Default: false
           Identity:  n/a

    Default value:
      false
    Returns:
      the value of the `wrap` property
    See Also:
      - `setWrap(boolean)`
      - `wrapProperty()`

  - ### wrapProperty

    public final BooleanProperty wrapProperty()
    Defines whether values taken from outside the edges of the map "wrap around" or not.

              Min:  n/a
              Max:  n/a
          Default: false
         Identity:  n/a

    Default value:
      false
    Returns:
      the `wrap` property
    See Also:
      - `isWrap()`
      - `setWrap(boolean)`