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();
});
});
}
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();
});
}
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();
}
});
}
Aggregations