mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Animate Methode zu play umbenannt
This commit is contained in:
@@ -3,7 +3,6 @@ package schule.ngb.zm.anim;
|
|||||||
import schule.ngb.zm.Color;
|
import schule.ngb.zm.Color;
|
||||||
import schule.ngb.zm.Constants;
|
import schule.ngb.zm.Constants;
|
||||||
import schule.ngb.zm.Vector;
|
import schule.ngb.zm.Vector;
|
||||||
import schule.ngb.zm.util.tasks.FrameSynchronizedTask;
|
|
||||||
import schule.ngb.zm.util.tasks.FramerateLimitedTask;
|
import schule.ngb.zm.util.tasks.FramerateLimitedTask;
|
||||||
import schule.ngb.zm.util.tasks.TaskRunner;
|
import schule.ngb.zm.util.tasks.TaskRunner;
|
||||||
import schule.ngb.zm.util.Log;
|
import schule.ngb.zm.util.Log;
|
||||||
@@ -125,28 +124,28 @@ public class Animations {
|
|||||||
public static final <T> Future<T> animateProperty( T target, final double from, final double to, int runtime, DoubleUnaryOperator easing, DoubleConsumer propSetter ) {
|
public static final <T> Future<T> animateProperty( T target, final double from, final double to, int runtime, DoubleUnaryOperator easing, DoubleConsumer propSetter ) {
|
||||||
Validator.requireNotNull(target);
|
Validator.requireNotNull(target);
|
||||||
Validator.requireNotNull(propSetter);
|
Validator.requireNotNull(propSetter);
|
||||||
return animate(target, runtime, easing, ( e ) -> propSetter.accept(Constants.interpolate(from, to, e)));
|
return play(target, runtime, easing, ( e ) -> propSetter.accept(Constants.interpolate(from, to, e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <T> Future<T> animateProperty( T target, final Color from, final Color to, int runtime, DoubleUnaryOperator easing, Consumer<Color> propSetter ) {
|
public static final <T> Future<T> animateProperty( T target, final Color from, final Color to, int runtime, DoubleUnaryOperator easing, Consumer<Color> propSetter ) {
|
||||||
return animate(target, runtime, easing, ( e ) -> propSetter.accept(Color.interpolate(from, to, e)));
|
return play(target, runtime, easing, ( e ) -> propSetter.accept(Color.interpolate(from, to, e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final <T> Future<T> animateProperty( T target, final Vector from, final Vector to, int runtime, DoubleUnaryOperator easing, Consumer<Vector> propSetter ) {
|
public static final <T> Future<T> animateProperty( T target, final Vector from, final Vector to, int runtime, DoubleUnaryOperator easing, Consumer<Vector> propSetter ) {
|
||||||
return animate(target, runtime, easing, ( e ) -> propSetter.accept(Vector.interpolate(from, to, e)));
|
return play(target, runtime, easing, ( e ) -> propSetter.accept(Vector.interpolate(from, to, e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <T, R> Future<T> animateProperty( T target, R from, R to, int runtime, DoubleUnaryOperator easing, DoubleFunction<R> interpolator, Consumer<R> propSetter ) {
|
public static final <T, R> Future<T> animateProperty( T target, R from, R to, int runtime, DoubleUnaryOperator easing, DoubleFunction<R> interpolator, Consumer<R> propSetter ) {
|
||||||
return animate(target, runtime, easing, interpolator, ( t, r ) -> propSetter.accept(r));
|
return play(target, runtime, easing, interpolator, ( t, r ) -> propSetter.accept(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final <T, R> Future<T> animate( T target, int runtime, DoubleUnaryOperator easing, DoubleFunction<R> interpolator, BiConsumer<T, R> applicator ) {
|
public static final <T, R> Future<T> play( T target, int runtime, DoubleUnaryOperator easing, DoubleFunction<R> interpolator, BiConsumer<T, R> applicator ) {
|
||||||
return animate(target, runtime, easing, ( e ) -> applicator.accept(target, interpolator.apply(e)));
|
return play(target, runtime, easing, ( e ) -> applicator.accept(target, interpolator.apply(e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <T> Future<T> animate( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) {
|
public static final <T> Future<T> play( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) {
|
||||||
return TaskRunner.run(new FramerateLimitedTask() {
|
return TaskRunner.run(new FramerateLimitedTask() {
|
||||||
double t = 0.0;
|
double t = 0.0;
|
||||||
|
|
||||||
@@ -167,8 +166,8 @@ public class Animations {
|
|||||||
}, target);
|
}, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <T> T animateAndWait( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) {
|
public static final <T> T playAndWait( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) {
|
||||||
Future<T> future = animate(target, runtime, easing, stepper);
|
Future<T> future = play(target, runtime, easing, stepper);
|
||||||
while( !future.isDone() ) {
|
while( !future.isDone() ) {
|
||||||
try {
|
try {
|
||||||
return future.get();
|
return future.get();
|
||||||
@@ -191,7 +190,8 @@ public class Animations {
|
|||||||
);
|
);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public static <T> Future<Animation<T>> animate( Animation<T> animation ) {
|
public static <T> Future<Animation<T>> play( Animation<T> animation ) {
|
||||||
|
// TODO: (ngb) Don't start when running
|
||||||
return TaskRunner.run(new FramerateLimitedTask() {
|
return TaskRunner.run(new FramerateLimitedTask() {
|
||||||
@Override
|
@Override
|
||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
@@ -206,13 +206,13 @@ public class Animations {
|
|||||||
}, animation);
|
}, animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Animation<T> animateAndWait( Animation<T> animation ) {
|
public static <T> Animation<T> playAndWait( Animation<T> animation ) {
|
||||||
Future<Animation<T>> future = animate(animation);
|
Future<Animation<T>> future = play(animation);
|
||||||
animation.await();
|
animation.await();
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Future<Animation<T>> animate( Animation<T> animation, DoubleUnaryOperator easing ) {
|
public static <T> Future<Animation<T>> play( Animation<T> animation, DoubleUnaryOperator easing ) {
|
||||||
final AnimationFacade<T> facade = new AnimationFacade<>(animation, animation.getRuntime(), easing);
|
final AnimationFacade<T> facade = new AnimationFacade<>(animation, animation.getRuntime(), easing);
|
||||||
return TaskRunner.run(new FramerateLimitedTask() {
|
return TaskRunner.run(new FramerateLimitedTask() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class AnimationsTest {
|
|||||||
|
|
||||||
private void _animateMove( Shape s, int runtime, DoubleUnaryOperator easing ) {
|
private void _animateMove( Shape s, int runtime, DoubleUnaryOperator easing ) {
|
||||||
s.moveTo(0, 0);
|
s.moveTo(0, 0);
|
||||||
Future<Shape> future = Animations.animate(
|
Future<Shape> future = Animations.play(
|
||||||
s, runtime,
|
s, runtime,
|
||||||
easing,
|
easing,
|
||||||
( e ) -> Constants.interpolate(0, zm.getWidth(), e),
|
( e ) -> Constants.interpolate(0, zm.getWidth(), e),
|
||||||
@@ -90,25 +90,11 @@ class AnimationsTest {
|
|||||||
final int midY = (int) (zm.getHeight() * .5);
|
final int midY = (int) (zm.getHeight() * .5);
|
||||||
final int radius = (int) (zm.getWidth() * .25);
|
final int radius = (int) (zm.getWidth() * .25);
|
||||||
|
|
||||||
Animator<Shape, Double> ani = new Animator<Shape, Double>() {
|
Future<Shape> future = Animations.play(
|
||||||
@Override
|
s, runtime, easing, (e) -> {
|
||||||
public double easing( double t ) {
|
double rad = Math.toRadians(Constants.interpolate(0, 360, e));
|
||||||
return easing.applyAsDouble(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double interpolator( double e ) {
|
|
||||||
return Constants.interpolate(0, 360, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applicator( Shape s, Double angle ) {
|
|
||||||
double rad = Math.toRadians(angle);
|
|
||||||
s.moveTo(midX + radius * Math.cos(rad), midY + radius * Math.sin(rad));
|
s.moveTo(midX + radius * Math.cos(rad), midY + radius * Math.sin(rad));
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
Future<Shape> future = Animations.animate(s, runtime, ani);
|
|
||||||
assertNotNull(future);
|
assertNotNull(future);
|
||||||
try {
|
try {
|
||||||
assertEquals(s, future.get());
|
assertEquals(s, future.get());
|
||||||
@@ -147,7 +133,7 @@ class AnimationsTest {
|
|||||||
private void _animateRotate( Shape s, int runtime, DoubleUnaryOperator easing ) {
|
private void _animateRotate( Shape s, int runtime, DoubleUnaryOperator easing ) {
|
||||||
s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5);
|
s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5);
|
||||||
s.rotateTo(0);
|
s.rotateTo(0);
|
||||||
Future<Shape> future = Animations.animate(
|
Future<Shape> future = Animations.play(
|
||||||
s, runtime,
|
s, runtime,
|
||||||
easing,
|
easing,
|
||||||
( e ) -> s.rotateTo(Constants.interpolate(0, 720, e))
|
( e ) -> s.rotateTo(Constants.interpolate(0, 720, e))
|
||||||
@@ -179,7 +165,7 @@ class AnimationsTest {
|
|||||||
private void _animateColor( Shape s, Color to, int runtime, DoubleUnaryOperator easing ) {
|
private void _animateColor( Shape s, Color to, int runtime, DoubleUnaryOperator easing ) {
|
||||||
s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5);
|
s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5);
|
||||||
final Color from = s.getFillColor();
|
final Color from = s.getFillColor();
|
||||||
Future<Shape> future = Animations.animate(
|
Future<Shape> future = Animations.play(
|
||||||
s, runtime,
|
s, runtime,
|
||||||
easing,
|
easing,
|
||||||
( e ) -> Color.interpolate(from, to, e),
|
( e ) -> Color.interpolate(from, to, e),
|
||||||
|
|||||||
Reference in New Issue
Block a user