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; }
private void compute(double w, double h){ FloatMap floatMap = new FloatMap(); int w1 = (int)w; int h1 = (int)h; floatMap.setWidth(w1); floatMap.setHeight(h1); for (int i = 0; i < w1; i++) { double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0; for (int j = 0; j < h1; j++) { floatMap.setSamples(i, j, 0.0f, (float) v); } } displacementMap.setMapData(floatMap); }
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); }
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); }
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); }
@Override public void start(Stage stage) throws Exception { this.stage = stage; configureScene(); configureStage(); // Logic starts for (int i = 0; i < BANNER_NB; i++) { maps[i] = new FloatMap(W, H); } for (int x = 0; x < W/2; x++) { double angle = Math.PI * x / 50.0; float v = (float) (Math.sin(angle) / 20.0); float scaledX = x / W; System.out.println(x + " : " + angle + " : " + v); for (int y = 0; y < H; y++) { float scaledY = y / H; float scaledV = (float) (v - (1.0 - scaledY) / 20.0); maps[0].setSamples(x, y, 0, 0); maps[1].setSamples(x, y, v); maps[2].setSamples(x, y, 0, scaledV); maps[3].setSamples(x, y, v, scaledV); double sq = Math.sqrt(x * x + y * y); maps[4].setSamples(x, y, (float) ((115 - sq) / 115.0)); maps[5].setSamples(x, y, 0, (float) (scaledX * scaledY * 4.7)); maps[6].setSamples(x, y, 0, (float) (scaledX * 0.5)); maps[7].setSamples(x, y, (float) (scaledY * 0.5)); } } String[] messages = { "Reference", "Accordion", "Wavy Text", "Dizzy Text", "OxoXoxO", "XoxOxoX", "13463463", "2346346436" }; VBox vb = new VBox(); vb.setSpacing(15); for (int k = 0; k < messages.length; k++) { vb.getChildren().add( GroupBuilder.create().effect(DisplacementMapBuilder.create().mapData(maps[k]).wrap(bTestWrap).build()).cache(true) .children(new Banner(messages[k])).build()); } root.getChildren().add( ScrollPaneBuilder.create().fitToHeight(true).fitToWidth(true).style("-fx-background-color:transparent;").content(vb) .build()); }