Package paintingcanvas.animation
Class Animation
- java.lang.Object
-
- paintingcanvas.animation.Animation
-
- Direct Known Subclasses:
ColorAnimation
,MovementAnimation
,OpacityAnimation
,RotationAnimation
public abstract class Animation extends java.lang.Object
A class that stores information about animations transitions
-
-
Field Summary
Fields Modifier and Type Field Description int
duration
The length of the animation in framesEasing
easing
The easing function to useint
startFrame
The frame at which the animation should start
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ColorAnimation
colorTo(int hex)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds.static ColorAnimation
colorTo(int r, int g, int b)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds.static Animation
colorTo(java.awt.Color color)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds.abstract Animation
copy()
Animation
easing(Easing easing)
Sets the easing to be used by this animationboolean
ended(int frame)
static OpacityAnimation
fadeIn()
Creates an animation that fadesthis
in over @{code duration} seconds.static OpacityAnimation
fadeOut()
Creates an animation that fadesthis
out over @{code duration} seconds.protected abstract void
initAnimation(Drawable<?> drawable)
Initialize the animation with the affected drawablestatic MovementAnimation
moveBy(int x, int y)
Creates an animation that movesthis
by the specifiedx
andy
static MovementAnimation
moveTo(int x, int y)
Creates an animation that movesthis
to the specifiedx
andy
overduration
secondsstatic RotationAnimation
rotateBy(int angle)
Creates an animation that rotatesthis
byangle°
.static RotationAnimation
rotateTo(int angle)
Creates an animation that rotatesthis
to the specifiedangle°
.void
update(int frame)
Updates the animation with the current frameprotected abstract void
updateAnimation(Drawable<?> drawable, double progress)
update the animation with the progress (0-1) and affected drawable
-
-
-
Field Detail
-
startFrame
public int startFrame
The frame at which the animation should start
-
duration
public int duration
The length of the animation in frames
-
easing
public Easing easing
The easing function to use
-
-
Method Detail
-
moveTo
public static MovementAnimation moveTo(int x, int y)
Creates an animation that movesthis
to the specifiedx
andy
overduration
secondsCircle c = new Circle(200, 200, 50); // the circle will move to (100, 100), and then to (200, 200) c.moveTo(100, 100, 3).moveTo(200, 200, 3);
- Parameters:
x
- the x-position to move toy
- the y-position to move to- Returns:
- a
MovementAnimation
-
colorTo
public static ColorAnimation colorTo(int r, int g, int b)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds. See Wikipedia for how this works.Circle c = new Circle(200, 200, 50); // the circle will turn red, and then blue c.colorTo(255, 0, 0, 3).colorTo(0, 0, 255, 3);
- Parameters:
r
- red (0-255)g
- green (0-255)b
- blue (0-255)- Returns:
- a
ColorAnimation
-
colorTo
public static ColorAnimation colorTo(int hex)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds. See Wikipedia for how this works.Circle c = new Circle(200, 200, 50); // the circle will turn red, and then blue c.colorTo(0xFF0000, 3).colorTo(0x0000FF, 3);
- Parameters:
hex
- The number describing the RGB color- Returns:
- a
ColorAnimation
-
colorTo
public static Animation colorTo(java.awt.Color color)
Creates an animation that changes the color ofthis
to the specifiedcolor
overduration
seconds. SeeColor
for the full list of colors, and constructors for this classCircle c = new Circle(200, 200, 50); // the circle will turn red, and then blue c.colorTo(Color.RED, 3).colorTo(Color.BLUE, 3);
- Parameters:
color
- The color to fade to- Returns:
- an
Animation
-
fadeOut
public static OpacityAnimation fadeOut()
Creates an animation that fadesthis
out over @{code duration} seconds.Circle c = new Circle(200, 200, 50); // the circle will fade out, then in c.fadeOut(3).fadeIn(3);
- Returns:
- an
OpacityAnimation
- See Also:
fadeIn()
-
fadeIn
public static OpacityAnimation fadeIn()
Creates an animation that fadesthis
in over @{code duration} seconds.Circle c = new Circle(200, 200, 50); // the circle will fade out, then in c.fadeOut(3).fadeIn(3);
- Returns:
- an
OpacityAnimation
- See Also:
fadeOut()
-
rotateTo
public static RotationAnimation rotateTo(int angle)
Creates an animation that rotatesthis
to the specifiedangle°
. If you supply an angle> 360
it will make more than one full rotation.Square s = new Square(200, 200, 50); // the square will rotate one turn counter-clockwise, then 2 turns clockwise c.rotateTo(360, 3).colorTo(-360, 3);
- Parameters:
angle
- The absolute angle to rotate to in degrees.- Returns:
- a
RotationAnimation
-
rotateBy
public static RotationAnimation rotateBy(int angle)
Creates an animation that rotatesthis
byangle°
.Square s = new Square(200, 200, 50); // the square will rotate one turn counter-clockwise, then one turns clockwise c.rotateTo(360, 3).colorTo(-360, 3);
- Parameters:
angle
- The relative angle to rotate to in degrees.- Returns:
- a
RotationAnimation
-
moveBy
public static MovementAnimation moveBy(int x, int y)
Creates an animation that movesthis
by the specifiedx
andy
Circle c = new Circle(200, 200, 50); // the circle will move down 100, and then right 200 c.moveTo(0, 100, 3).moveTo(200, 0, 3);
- Parameters:
x
- the x to move byy
- the y to move by- Returns:
- a
MovementAnimation
-
copy
public abstract Animation copy()
-
easing
public Animation easing(Easing easing)
Sets the easing to be used by this animation- Parameters:
easing
- the easing to be used- Returns:
- this
-
update
public void update(int frame)
Updates the animation with the current frame- Parameters:
frame
- the current frame
-
updateAnimation
protected abstract void updateAnimation(Drawable<?> drawable, double progress)
update the animation with the progress (0-1) and affected drawable- Parameters:
drawable
- The affected drawableprogress
- Animation progress (0-1)
-
initAnimation
protected abstract void initAnimation(Drawable<?> drawable)
Initialize the animation with the affected drawable- Parameters:
drawable
- The affected drawable
-
ended
public boolean ended(int frame)
-
-