Search in sources :

Example 6 with Texture

use of com.almasb.fxgl.texture.Texture in project FXGL by AlmasB.

the class ColoringSample method initUI.

@Override
protected void initUI() {
    getGameScene().setBackgroundColor(Color.color(0.75, 0.75, 0.75));
    Texture original = texture("player2.png");
    // long start = System.nanoTime();
    // 
    // original.blend(new Rectangle(100, 100, Color.RED), BlendMode.ADD);
    // 
    // System.out.println(System.nanoTime() - start);
    // 
    // start = System.nanoTime();
    // 
    // original.manualBlend(new Rectangle(100, 100, Color.RED), BlendMode.ADD);
    // 
    // System.out.println(System.nanoTime() - start);
    LinearGradient gradient = new LinearGradient(0.5, 0, 0.5, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.RED), new Stop(1, Color.YELLOW));
    EntityView view = new EntityView();
    Texture outline1 = original.toColor(Color.BLACK);
    view.addNode(outline1);
    outline1.setTranslateX(1);
    Texture outline2 = original.toColor(Color.BLACK);
    view.addNode(outline2);
    outline2.setTranslateX(-1);
    Texture outline3 = original.toColor(Color.BLACK);
    view.addNode(outline3);
    outline3.setTranslateY(1);
    Texture outline4 = original.toColor(Color.BLACK);
    view.addNode(outline4);
    outline4.setTranslateY(-1);
    view.addNode(original.copy());
    HBox hbox = new HBox(20, makeBox("Original", original), makeBox("Outline", view), // makeBox("Grayscale", original.toGrayscale()),
    makeBox("Darker", original.darker()), makeBox("Brighter", original.brighter()), makeBox("Invert", original.invert()), makeBox("Saturate", original.saturate().saturate().saturate()));
    HBox hbox2 = new HBox(20, makeBox("Soft: self", original.blend(original.copy(), BlendMode.SOFT_LIGHT)), makeBox("Add: red", original.blend(new Rectangle(200, 100, Color.RED), BlendMode.ADD)), makeBox("Red on blue", original.blend(new Rectangle(200, 100, Color.BLUE), BlendMode.RED)), makeBox("Color: red", original.toColor(Color.RED)), makeBox("Mult: red", original.multiplyColor(Color.RED)), makeBox("Screen: RY", original.blend(new Rectangle(200, 100, gradient), BlendMode.SCREEN)));
    Texture brick1 = texture("brick.png");
    brick1.setScaleX(1.5);
    brick1.setScaleY(1.5);
    Texture brick2 = texture("brick.png");
    brick2.setScaleX(1.5);
    brick2.setScaleY(1.5);
    Texture brick3 = texture("brick.png");
    brick3.setScaleX(1.5);
    brick3.setScaleY(1.5);
    Texture brick4 = texture("brick.png");
    brick4.setScaleX(1.5);
    brick4.setScaleY(1.5);
    Texture ship1 = original.copy();
    ship1.setScaleX(0.7);
    ship1.setScaleY(0.7);
    HBox hbox3 = new HBox(20, makeBox("Texture 2", texture("brick.png")), makeBox("Diff", original.blend(brick1, BlendMode.DIFFERENCE)), makeBox("Diff^-1", brick3.blend(ship1, BlendMode.DIFFERENCE)), makeBox("Overlay", original.blend(brick2, BlendMode.OVERLAY)), makeBox("Exclusion", original.blend(brick4, BlendMode.EXCLUSION)));
    hbox.setTranslateY(50);
    hbox2.setTranslateY(250);
    hbox3.setTranslateY(450);
    Text t = getUIFactory().newText("Texture v Texture Blend", Color.WHITE, 24);
    getUIFactory().centerText(t, getWidth() / 2, getHeight() - 150);
    getGameScene().addUINodes(hbox, hbox2, hbox3, t);
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) HBox(javafx.scene.layout.HBox) Stop(javafx.scene.paint.Stop) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) Texture(com.almasb.fxgl.texture.Texture)

Example 7 with Texture

use of com.almasb.fxgl.texture.Texture in project FXGL by AlmasB.

the class QuadSample method initGame.

@Override
protected void initGame() {
    getGameScene().setBackgroundColor(Color.BLACK);
    Texture ship = texture("player2.png");
    double h = 7;
    System.out.println(h);
    for (int i = 0; i < 10; i++) {
        Texture quad = ship.subTexture(new Rectangle2D(0, i * h, ship.getImage().getWidth(), h));
        quad.setTranslateY(100 + i * h);
        originals.add(quad);
        textures.add(quad.copy());
        textures2.add(quad.toColor(Color.RED));
        getGameScene().addUINode(quad);
    }
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Texture(com.almasb.fxgl.texture.Texture)

Example 8 with Texture

use of com.almasb.fxgl.texture.Texture in project FXGL by AlmasB.

the class MapGenerationSample method variety.

private void variety() {
    // tile size
    int size = 5;
    int W = getWidth() / size;
    int H = getHeight() / size;
    HeightMapGenerator gen = new HeightMapGenerator(2.4);
    gen.setGenFunction((nx, ny, freq) -> {
        double e = FXGLMath.noise2D(nx, ny) + 0.5 * FXGLMath.noise2D(2 * nx, 2 * ny) + 0.25 * FXGLMath.noise2D(9 * nx, 9 * ny);
        double noiseValue = Math.pow(e, 3.3);
        if (noiseValue < 0) {
            noiseValue = 0;
        }
        if (noiseValue > 1) {
            noiseValue = 1;
        }
        return noiseValue;
    });
    Grid<Double> map = gen.generate(W, H);
    map.forEach((data, x, y) -> {
        Texture texture;
        if (data < 0.2) {
            // water
            texture = new Texture(new WritableImage(size, size)).replaceColor(Color.TRANSPARENT, Color.BLUE);
        } else if (data < 0.8) {
            // grass
            texture = DSLKt.texture("grass.png", size, size);
        } else {
            // in-land grass / mud?
            texture = DSLKt.texture("grass.png", size, size).desaturate().brighter().desaturate();
        }
        Entities.builder().at(x * size, y * size).viewFromNode(texture).buildAndAttach();
    });
}
Also used : WritableImage(javafx.scene.image.WritableImage) HeightMapGenerator(com.almasb.fxgl.algorithm.procedural.HeightMapGenerator) Texture(com.almasb.fxgl.texture.Texture)

Example 9 with Texture

use of com.almasb.fxgl.texture.Texture in project FXGL by AlmasB.

the class MapGenerationSample method plain.

private void plain() {
    // tile size
    int size = 5;
    int W = getWidth() / size;
    int H = getHeight() / size;
    MapGenerator<BiomeMapGenerator.BiomeData> gen = new BiomeMapGenerator(2.4);
    Grid<BiomeMapGenerator.BiomeData> map = gen.generate(W, H);
    map.forEach((data, x, y) -> {
        Texture texture;
        if (data.getElevation() < 0.2) {
            // water
            texture = new Texture(new WritableImage(size, size)).replaceColor(Color.TRANSPARENT, Color.BLUE);
        } else if (data.getElevation() < 0.8) {
            // grass
            texture = DSLKt.texture("grass.png", size, size);
        } else {
            // in-land grass / mud?
            texture = DSLKt.texture("grass.png", size, size).desaturate().brighter().desaturate();
        }
        Entities.builder().at(x * size, y * size).viewFromNode(texture).buildAndAttach();
    });
}
Also used : BiomeMapGenerator(com.almasb.fxgl.algorithm.procedural.BiomeMapGenerator) WritableImage(javafx.scene.image.WritableImage) Texture(com.almasb.fxgl.texture.Texture)

Example 10 with Texture

use of com.almasb.fxgl.texture.Texture in project FXGL by AlmasB.

the class MapGenerationSample method coloredMap.

private void coloredMap() {
    // tile size
    int size = 1;
    int W = getWidth() / size;
    int H = getHeight() / size;
    HeightMapGenerator gen = new HeightMapGenerator(2.4);
    gen.setGenFunction((nx, ny, freq) -> {
        double e = FXGLMath.noise2D(nx, ny) + 0.5 * FXGLMath.noise2D(2 * nx, 2 * ny) + 0.25 * FXGLMath.noise2D(9 * nx, 9 * ny);
        double noiseValue = Math.pow(e, 3.3);
        if (noiseValue < 0) {
            noiseValue = 0;
        }
        if (noiseValue > 1) {
            noiseValue = 1;
        }
        return noiseValue;
    });
    Grid<Double> map = gen.generate(W, H);
    // use different interpolators if needed
    AnimatedColor water = new AnimatedColor(Color.DARKBLUE, Color.AQUA, Interpolators.LINEAR.EASE_OUT());
    AnimatedColor land = new AnimatedColor(Color.DARKGREEN, Color.LIGHTGREEN, Interpolators.LINEAR.EASE_OUT());
    AnimatedColor desert = new AnimatedColor(Color.YELLOW, Color.LIGHTYELLOW);
    AnimatedColor snow = new AnimatedColor(Color.BROWN, Color.WHITESMOKE);
    WritableImage image = new WritableImage(W, H);
    map.forEach((data, x, y) -> {
        AnimatedColor anim;
        if (data < 0.2) {
            anim = water;
        } else if (data < 0.4) {
            anim = land;
        } else if (data < 0.8) {
            anim = desert;
        } else {
            anim = snow;
        }
        image.getPixelWriter().setColor(x, y, anim.getValue(data));
    });
    getGameScene().addUINode(new Texture(image));
}
Also used : AnimatedColor(com.almasb.fxgl.animation.AnimatedColor) WritableImage(javafx.scene.image.WritableImage) HeightMapGenerator(com.almasb.fxgl.algorithm.procedural.HeightMapGenerator) Texture(com.almasb.fxgl.texture.Texture)

Aggregations

Texture (com.almasb.fxgl.texture.Texture)10 Text (javafx.scene.text.Text)4 WritableImage (javafx.scene.image.WritableImage)3 HeightMapGenerator (com.almasb.fxgl.algorithm.procedural.HeightMapGenerator)2 Entity (com.almasb.fxgl.entity.Entity)2 BiomeMapGenerator (com.almasb.fxgl.algorithm.procedural.BiomeMapGenerator)1 AnimatedColor (com.almasb.fxgl.animation.AnimatedColor)1 Interpolators (com.almasb.fxgl.animation.Interpolators)1 EntityView (com.almasb.fxgl.entity.view.EntityView)1 Point2D (javafx.geometry.Point2D)1 Rectangle2D (javafx.geometry.Rectangle2D)1 HBox (javafx.scene.layout.HBox)1 Pane (javafx.scene.layout.Pane)1 LinearGradient (javafx.scene.paint.LinearGradient)1 Stop (javafx.scene.paint.Stop)1 Line (javafx.scene.shape.Line)1 Rectangle (javafx.scene.shape.Rectangle)1