From aceb79c44f455e15efe6c7286a8a7a61bd8d662f Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Mon, 25 Jul 2022 17:40:42 +0200 Subject: [PATCH] Animate Methode zu play umbenannt --- .../java/schule/ngb/zm/anim/Animations.java | 28 +++++++++---------- .../schule/ngb/zm/anim/AnimationsTest.java | 28 +++++-------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/main/java/schule/ngb/zm/anim/Animations.java b/src/main/java/schule/ngb/zm/anim/Animations.java index fb332e2..533e129 100644 --- a/src/main/java/schule/ngb/zm/anim/Animations.java +++ b/src/main/java/schule/ngb/zm/anim/Animations.java @@ -3,7 +3,6 @@ package schule.ngb.zm.anim; import schule.ngb.zm.Color; import schule.ngb.zm.Constants; 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.TaskRunner; import schule.ngb.zm.util.Log; @@ -125,28 +124,28 @@ public class Animations { public static final Future animateProperty( T target, final double from, final double to, int runtime, DoubleUnaryOperator easing, DoubleConsumer propSetter ) { Validator.requireNotNull(target); 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 Future animateProperty( T target, final Color from, final Color to, int runtime, DoubleUnaryOperator easing, Consumer 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 Future animateProperty( T target, final Vector from, final Vector to, int runtime, DoubleUnaryOperator easing, Consumer 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 Future animateProperty( T target, R from, R to, int runtime, DoubleUnaryOperator easing, DoubleFunction interpolator, Consumer 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 Future animate( T target, int runtime, DoubleUnaryOperator easing, DoubleFunction interpolator, BiConsumer applicator ) { - return animate(target, runtime, easing, ( e ) -> applicator.accept(target, interpolator.apply(e))); + public static final Future play( T target, int runtime, DoubleUnaryOperator easing, DoubleFunction interpolator, BiConsumer applicator ) { + return play(target, runtime, easing, ( e ) -> applicator.accept(target, interpolator.apply(e))); } - public static final Future animate( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) { + public static final Future play( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) { return TaskRunner.run(new FramerateLimitedTask() { double t = 0.0; @@ -167,8 +166,8 @@ public class Animations { }, target); } - public static final T animateAndWait( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) { - Future future = animate(target, runtime, easing, stepper); + public static final T playAndWait( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) { + Future future = play(target, runtime, easing, stepper); while( !future.isDone() ) { try { return future.get(); @@ -191,7 +190,8 @@ public class Animations { ); }*/ - public static Future> animate( Animation animation ) { + public static Future> play( Animation animation ) { + // TODO: (ngb) Don't start when running return TaskRunner.run(new FramerateLimitedTask() { @Override protected void initialize() { @@ -206,13 +206,13 @@ public class Animations { }, animation); } - public static Animation animateAndWait( Animation animation ) { - Future> future = animate(animation); + public static Animation playAndWait( Animation animation ) { + Future> future = play(animation); animation.await(); return animation; } - public static Future> animate( Animation animation, DoubleUnaryOperator easing ) { + public static Future> play( Animation animation, DoubleUnaryOperator easing ) { final AnimationFacade facade = new AnimationFacade<>(animation, animation.getRuntime(), easing); return TaskRunner.run(new FramerateLimitedTask() { @Override diff --git a/src/test/java/schule/ngb/zm/anim/AnimationsTest.java b/src/test/java/schule/ngb/zm/anim/AnimationsTest.java index e01e228..21cb20e 100644 --- a/src/test/java/schule/ngb/zm/anim/AnimationsTest.java +++ b/src/test/java/schule/ngb/zm/anim/AnimationsTest.java @@ -61,7 +61,7 @@ class AnimationsTest { private void _animateMove( Shape s, int runtime, DoubleUnaryOperator easing ) { s.moveTo(0, 0); - Future future = Animations.animate( + Future future = Animations.play( s, runtime, easing, ( e ) -> Constants.interpolate(0, zm.getWidth(), e), @@ -90,25 +90,11 @@ class AnimationsTest { final int midY = (int) (zm.getHeight() * .5); final int radius = (int) (zm.getWidth() * .25); - Animator ani = new Animator() { - @Override - public double easing( double t ) { - 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); + Future future = Animations.play( + s, runtime, easing, (e) -> { + double rad = Math.toRadians(Constants.interpolate(0, 360, e)); s.moveTo(midX + radius * Math.cos(rad), midY + radius * Math.sin(rad)); - } - }; - - Future future = Animations.animate(s, runtime, ani); + }); assertNotNull(future); try { assertEquals(s, future.get()); @@ -147,7 +133,7 @@ class AnimationsTest { private void _animateRotate( Shape s, int runtime, DoubleUnaryOperator easing ) { s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5); s.rotateTo(0); - Future future = Animations.animate( + Future future = Animations.play( s, runtime, easing, ( 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 ) { s.moveTo(zm.getWidth() * .5, zm.getHeight() * .5); final Color from = s.getFillColor(); - Future future = Animations.animate( + Future future = Animations.play( s, runtime, easing, ( e ) -> Color.interpolate(from, to, e),