diff --git a/src/main/java/paintingcanvas/animation/Animation.java b/src/main/java/paintingcanvas/animation/Animation.java index efb264e..95ed951 100644 --- a/src/main/java/paintingcanvas/animation/Animation.java +++ b/src/main/java/paintingcanvas/animation/Animation.java @@ -135,7 +135,7 @@ public static OpacityAnimation fadeOut() { * @see #fadeOut() */ public static OpacityAnimation fadeIn() { - return new OpacityAnimation(1); + return new OpacityAnimation(255); } /** diff --git a/src/main/java/paintingcanvas/animation/ColorAnimation.java b/src/main/java/paintingcanvas/animation/ColorAnimation.java index b31bf76..b2c2faa 100644 --- a/src/main/java/paintingcanvas/animation/ColorAnimation.java +++ b/src/main/java/paintingcanvas/animation/ColorAnimation.java @@ -48,6 +48,6 @@ Color lerpColor(Color _a, Color _b, double delta) { var b = _a.getBlue() + (_b.getBlue() - _a.getBlue()) * delta; var a = _a.getAlpha() + (_b.getAlpha() - _a.getAlpha()) * delta; - return new Color(Misc.clamp((int) r, 0, 255), Misc.clamp((int) g, 0, 255), Misc.clamp((int) b, 0, 255), Misc.clamp((int) a, 0, 255)); + return new Color(Misc.clamp(0, (int) r, 255), Misc.clamp(0, (int) g, 255), Misc.clamp(255, (int) b, 255), Misc.clamp(0, (int) a, 255)); } } diff --git a/src/main/java/paintingcanvas/animation/OpacityAnimation.java b/src/main/java/paintingcanvas/animation/OpacityAnimation.java index 30d7faf..a6a4784 100644 --- a/src/main/java/paintingcanvas/animation/OpacityAnimation.java +++ b/src/main/java/paintingcanvas/animation/OpacityAnimation.java @@ -18,28 +18,38 @@ public OpacityAnimation(double end) { this.end = (int) (end * 255.0); } + public OpacityAnimation(int end) { + super(); + this.end = end; + } + @Override public Animation copy() { - var out = new OpacityAnimation(end); + var out = new OpacityAnimation(this.end); out.copy(this); return out; } @Override protected void updateAnimation(Drawable> drawable, double progress) { + var t = easing.ease(progress); + Color color = drawable.color; - int alpha = (int) (start + (end - start) * easing.ease(progress)); + int alpha = (int) (start + (end - start) * t); +// System.err.println(end); + alpha = Misc.clamp(0, alpha, 255); drawable.color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); Color outlineColor = drawable.outlineColor; - int outlineAlpha = (int) (start + (end - start) * easing.ease(progress)); - outlineAlpha = Misc.clamp(outlineAlpha, 0, 255); + int outlineAlpha = (int) (start + (end - start) * t); + outlineAlpha = Misc.clamp(0, outlineAlpha, 255); drawable.outlineColor = new Color(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue(), outlineAlpha); } @Override protected void initAnimation(Drawable> drawable) { this.start = drawable.color.getAlpha(); +// System.out.println(start); this.outlineStart = drawable.outlineColor.getAlpha(); } } diff --git a/src/main/java/paintingcanvas/misc/Misc.java b/src/main/java/paintingcanvas/misc/Misc.java index d2223c3..4e7e201 100644 --- a/src/main/java/paintingcanvas/misc/Misc.java +++ b/src/main/java/paintingcanvas/misc/Misc.java @@ -1,7 +1,7 @@ package paintingcanvas.misc; public class Misc { - public static N clamp(N val, N min, N max) { + public static N clamp(N min, N val, N max) { if (val.doubleValue() > max.doubleValue()) return max; if (val.doubleValue() < min.doubleValue()) return min; return val; diff --git a/src/test/java/examples/Test.java b/src/test/java/examples/Test.java index 0424ff7..b527b9e 100644 --- a/src/test/java/examples/Test.java +++ b/src/test/java/examples/Test.java @@ -18,14 +18,17 @@ public static void main(String[] args) { Line l = new Line(0, 0, 100, 100, Color.RED).setColor(Color.blue); Circle c = new Circle(canvas.getWidth() / 2, canvas.getHeight() / 2, 50, Color.RED); while (true) { - c.moveBy(100, 1, 1); - canvas.sleep(1); - c.moveBy(0, 100, 1); - canvas.sleep(1); - c.moveBy(-100, 1, 1); - canvas.sleep(1); - c.moveBy(0, -100, 1); - canvas.sleep(1); +// c.moveHorizontalBy(100, 1); +// canvas.sleep(1); +// c.moveVerticalBy(100, 1); +// canvas.sleep(1); +// c.moveHorizontalBy(-100, 1); +// canvas.sleep(1); +// c.moveVerticalBy(-100, 1); +// canvas.sleep(1); + c.fadeOut(1); + c.fadeIn(1); + c.colorTo(Color.BLUE, 2); } } }