Java 类javafx.scene.effect.DisplacementMap 实例源码

项目:openjfx-8u-dev-tests    文件:CanvasEffects2App.java   
List<NamedEffect> getNamedEffectList() {
    final FloatMap mapWaves = new FloatMap();
    mapWaves.setWidth(100);
    mapWaves.setHeight(80);
    for (int i = 0; i < mapWaves.getWidth()-1; i++) {
        float v = (float) ((Math.sin(i / 30f * Math.PI) - 0.5f) / 20f);
        for (int j = 0; j < mapWaves.getHeight()-1; j++) {
            mapWaves.setSamples(i, j, 0f, v);
        }
    }

    List<NamedEffect> nes = new ArrayList<NamedEffect>();
    nes.add(new NamedEffect("defaults", new DisplacementMap() {{ setMapData(mapWaves); }}));
    nes.add(new NamedEffect("scale",  new DisplacementMap() {{ setMapData(mapWaves); setScaleX(1.2f); setScaleY(2.0f);}}));
    nes.add(new NamedEffect("offset",  new DisplacementMap() {{ setMapData(mapWaves); setOffsetX(0.2f); setOffsetY(0.1f);}}));
    nes.add(new NamedEffect("wrap",  new DisplacementMap() {{ setMapData(mapWaves); setWrap(true); setOffsetX(0.5f); setOffsetY(0.3f);}}));
    return nes;
}
项目:javafx-demos    文件:ScrollPaneDisplacementDemo.java   
private void applyEffect(ScrollPane scroll) {
    DisplacementMap displacementMap = new DisplacementMap();
    FloatMap floatMap = new FloatMap((int) width, (int) height);
    for (int i = 0; i < (int) width; i++) {
        double v = (Math.sin(i / 50.0 * Math.PI) - 1) / 10.0;
        for (int j = 0; j < (int) height; j++) {
            floatMap.setSamples(i, j, 0, (float) v);
        }
    }
    displacementMap.setMapData(floatMap);
    scroll.setEffect(displacementMap);
}
项目:javafx-demos    文件:ScrollPaneDisplacementDemo.java   
private void applyCosWaveEffect(ScrollPane scroll) {
    DisplacementMap displacementMap = new DisplacementMap();
    FloatMap floatMap = new FloatMap((int) width, (int) height);
    for (int i = 0; i < (int) width; i++) {
        double v = (Math.cos(i / 20.0 * Math.PI) - 0.5) / 40.0;
        for (int j = 0; j < (int) height; j++) {
            floatMap.setSamples(i, j, 0, (float) v);
        }
    }
    displacementMap.setMapData(floatMap);
    scroll.setEffect(displacementMap);
}
项目:javafx-demos    文件:ScrollPaneDisplacementDemo.java   
private void applySineWaveEffect(ScrollPane scroll) {
    DisplacementMap displacementMap = new DisplacementMap();
    FloatMap floatMap = new FloatMap((int) width, (int) height);
    for (int i = 0; i < (int) width; i++) {
        double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0;
        for (int j = 0; j < (int) height; j++) {
            floatMap.setSamples(i, j, 0, (float) v);
        }
    }
    displacementMap.setMapData(floatMap);
    scroll.setEffect(displacementMap);
}