Search in sources :

Example 1 with AnimatedValue

use of com.almasb.fxgl.animation.AnimatedValue in project FXGL by AlmasB.

the class CrystalApp2 method initInput.

@Override
protected void initInput() {
    onKeyDown(KeyCode.F, () -> {
        delayIndex = 0.0;
        var point = FXGLMath.randomPoint(new Rectangle2D(0, 0, getAppWidth() - 200, getAppHeight() - 200));
        pixels.stream().sorted(Comparator.comparingDouble(p -> p.getLayoutY())).forEach(p -> {
            animationBuilder().duration(Duration.seconds(0.2)).interpolator(Interpolators.EXPONENTIAL.EASE_OUT()).onFinished(() -> {
                animationBuilder().delay(Duration.seconds(random(0.1, 0.6))).onFinished(() -> {
                    animationBuilder().delay(Duration.seconds(random(delayIndex, delayIndex + 0.1))).duration(Duration.seconds(1.5)).interpolator(Interpolators.ELASTIC.EASE_OUT()).translate(p).from(new Point2D(p.getTranslateX(), p.getTranslateY())).to(point).buildAndPlay();
                    delayIndex += 0.0001;
                }).duration(Duration.seconds(0.75)).interpolator(Interpolators.RANDOM.EASE_OUT()).animate(new AnimatedValue<>(0.0, 1.0)).onProgress(progress -> {
                    var x = p.getTranslateX();
                    var y = p.getTranslateY();
                    var noiseValue = FXGLMath.noise2D(x * 0.002 * progress, y * 0.002 * t);
                    var angle = FXGLMath.toDegrees((noiseValue + 1) * Math.PI * random(1.0, 6.0));
                    angle %= 360.0;
                    var v = Vec2.fromAngle(angle).normalizeLocal().mulLocal(FXGLMath.random(1.0, 25));
                    Vec2 velocity = (Vec2) p.getProperties().get("vel");
                    var vx = velocity.x * 0.8f + v.x * 0.2f;
                    var vy = velocity.y * 0.8f + v.y * 0.2f;
                    velocity.x = vx;
                    velocity.y = vy;
                    p.setTranslateX(x + velocity.x);
                    p.setTranslateY(y + velocity.y);
                }).buildAndPlay();
            }).scale(p).from(new Point2D(1, 1)).to(new Point2D(3, 3)).buildAndPlay();
        });
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Rectangle2D(javafx.geometry.Rectangle2D) CubicCurve(javafx.scene.shape.CubicCurve) Node(javafx.scene.Node) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Duration(javafx.util.Duration) List(java.util.List) Interpolators(com.almasb.fxgl.animation.Interpolators) AnimatedValue(com.almasb.fxgl.animation.AnimatedValue) GameSettings(com.almasb.fxgl.app.GameSettings) Vec2(com.almasb.fxgl.core.math.Vec2) Point2D(javafx.geometry.Point2D) ImagesKt(com.almasb.fxgl.texture.ImagesKt) Comparator(java.util.Comparator) GameApplication(com.almasb.fxgl.app.GameApplication) FXGL(com.almasb.fxgl.dsl.FXGL) Point2D(javafx.geometry.Point2D) Vec2(com.almasb.fxgl.core.math.Vec2) Rectangle2D(javafx.geometry.Rectangle2D)

Example 2 with AnimatedValue

use of com.almasb.fxgl.animation.AnimatedValue in project FXGL by AlmasB.

the class ParticleMorphApp method initInput.

@Override
protected void initInput() {
    onKeyDown(KeyCode.F, () -> {
        delayIndex = 0.0;
        pixels.stream().sorted(Comparator.comparingDouble(p -> p.getLayoutY())).forEach(p -> {
            // p.setBlendMode(BlendMode.ADD);
            animationBuilder().duration(Duration.seconds(0.2)).interpolator(Interpolators.EXPONENTIAL.EASE_OUT()).onFinished(() -> {
                animationBuilder().delay(Duration.seconds(random(0.1, 0.6))).onFinished(() -> {
                    animationBuilder().delay(Duration.seconds(random(delayIndex, delayIndex + 0.1))).duration(Duration.seconds(1.5)).interpolator(Interpolators.EXPONENTIAL.EASE_IN()).translate(p).alongPath(new CubicCurve(p.getTranslateX(), p.getTranslateY(), random(200, 300), random(-200, 20), random(600, 700), random(500, 700), 650, 150)).buildAndPlay();
                    delayIndex += 0.0001;
                }).duration(Duration.seconds(0.75)).interpolator(Interpolators.BOUNCE.EASE_OUT()).animate(new AnimatedValue<>(0.0, 1.0)).onProgress(progress -> {
                    var x = p.getTranslateX();
                    var y = p.getTranslateY();
                    var noiseValue = FXGLMath.noise2D(x * 0.002 * progress, y * 0.002 * t);
                    var angle = FXGLMath.toDegrees((noiseValue + 1) * Math.PI * 1.5);
                    angle %= 360.0;
                    var v = Vec2.fromAngle(angle).normalizeLocal().mulLocal(FXGLMath.random(1.0, 25));
                    Vec2 velocity = (Vec2) p.getProperties().get("vel");
                    var vx = velocity.x * 0.8f + v.x * 0.2f;
                    var vy = velocity.y * 0.8f + v.y * 0.2f;
                    velocity.x = vx;
                    velocity.y = vy;
                    p.setTranslateX(x + velocity.x);
                    p.setTranslateY(y + velocity.y);
                }).buildAndPlay();
            }).scale(p).from(new Point2D(1, 1)).to(new Point2D(3, 3)).buildAndPlay();
        });
    });
    onKeyDown(KeyCode.G, () -> {
        morph();
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Rectangle2D(javafx.geometry.Rectangle2D) CubicCurve(javafx.scene.shape.CubicCurve) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) Rectangle(javafx.scene.shape.Rectangle) Collectors(java.util.stream.Collectors) Duration(javafx.util.Duration) List(java.util.List) Interpolators(com.almasb.fxgl.animation.Interpolators) AnimatedValue(com.almasb.fxgl.animation.AnimatedValue) GameSettings(com.almasb.fxgl.app.GameSettings) Vec2(com.almasb.fxgl.core.math.Vec2) Point2D(javafx.geometry.Point2D) ImagesKt(com.almasb.fxgl.texture.ImagesKt) Comparator(java.util.Comparator) GameApplication(com.almasb.fxgl.app.GameApplication) FXGL(com.almasb.fxgl.dsl.FXGL) CubicCurve(javafx.scene.shape.CubicCurve) Point2D(javafx.geometry.Point2D) Vec2(com.almasb.fxgl.core.math.Vec2)

Example 3 with AnimatedValue

use of com.almasb.fxgl.animation.AnimatedValue in project FXGL by AlmasB.

the class CirclesSample method initInput.

@Override
protected void initInput() {
    onKeyDown(KeyCode.F, () -> {
        getGameWorld().getEntitiesCopy().forEach(Entity::removeFromWorld);
        for (int i = 0; i < interpolators.size(); i++) {
            var interpolator = interpolators.get(i);
            var box = new Box(1, 1, 1);
            box.setMaterial(new PhongMaterial(Color.BLUE));
            var c = entityBuilder().view(box).buildAndAttach();
            var center = new Point2D(0, 0);
            var point = new Point2D(2 + i * 1, 0.0).add(center);
            animationBuilder().duration(Duration.seconds(8)).interpolator(interpolator).animate(new AnimatedValue<>(0.0, 360.0)).onProgress(deg -> {
                var p = FXGLMath.rotate(point, center, deg);
                c.setX(p.getX());
                c.setY(p.getY());
            }).buildAndPlay();
        }
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Point3D(javafx.geometry.Point3D) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) ArrayList(java.util.ArrayList) Box(javafx.scene.shape.Box) Duration(javafx.util.Duration) List(java.util.List) Interpolator(javafx.animation.Interpolator) PhongMaterial(javafx.scene.paint.PhongMaterial) Interpolators(com.almasb.fxgl.animation.Interpolators) AnimatedValue(com.almasb.fxgl.animation.AnimatedValue) GameSettings(com.almasb.fxgl.app.GameSettings) Point2D(javafx.geometry.Point2D) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) FXGL(com.almasb.fxgl.dsl.FXGL) Entity(com.almasb.fxgl.entity.Entity) Point2D(javafx.geometry.Point2D) Box(javafx.scene.shape.Box) PhongMaterial(javafx.scene.paint.PhongMaterial)

Aggregations

AnimatedValue (com.almasb.fxgl.animation.AnimatedValue)3 Interpolators (com.almasb.fxgl.animation.Interpolators)3 GameApplication (com.almasb.fxgl.app.GameApplication)3 GameSettings (com.almasb.fxgl.app.GameSettings)3 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)3 FXGL (com.almasb.fxgl.dsl.FXGL)3 List (java.util.List)3 Point2D (javafx.geometry.Point2D)3 KeyCode (javafx.scene.input.KeyCode)3 Color (javafx.scene.paint.Color)3 Duration (javafx.util.Duration)3 Vec2 (com.almasb.fxgl.core.math.Vec2)2 ImagesKt (com.almasb.fxgl.texture.ImagesKt)2 Comparator (java.util.Comparator)2 Collectors (java.util.stream.Collectors)2 Rectangle2D (javafx.geometry.Rectangle2D)2 CubicCurve (javafx.scene.shape.CubicCurve)2 Rectangle (javafx.scene.shape.Rectangle)2 Entity (com.almasb.fxgl.entity.Entity)1 ArrayList (java.util.ArrayList)1