edu.umd.cs.jazz.animation
Class ZColorAnimation

java.lang.Object
  |
  +--edu.umd.cs.jazz.animation.ZAnimation
        |
        +--edu.umd.cs.jazz.animation.ZColorAnimation

public class ZColorAnimation
extends ZAnimation

ZColorAnimation animates an object conforming to the ZFillPaint or ZPenPaint interface from a source color to a destination color over time. A ZAlpha class is used to specify the start time, duration, and acceleration time for this animation.

This example code demonstrates how to animate the fill color of a rectangle from color red to color yellow.

 ZRectangle aRect = new ZRectangle(0, 0, 100, 100);
 ZVisualLeaf aLeaf = new ZVisualLeaf(aRect);

 canvas.getLayer().addChild(aLeaf);

 // Create a new ZAlpha that will run from the current time for 1.5 seconds.
 // This alpha will change linearly; see the ZAlpha class to learn how to create
 // slow in slow out animation effects.
 ZAlpha alpha = new ZAlpha(1, 1500);

 // Create the ZColorAnimation with its source and destination values. Here
 // we choose to animate the target from color red to color yellow.
 ZColorAnimation aColorAnimation = new ZColorAnimation(Color.red, Color.yellow);

 // Set the target of the animation.
 aColorAnimation.setFillPaintTarget(aRect);

 // Set the alpha value for the animation. This animation will start immediately,
 // and run for 1.5 seconds.
 aColorAnimation.setAlpha(alpha);

 // Start the animation by registering it with the ZAnimationScheduler.
 aColorAnimation.play();
 

Author:
Jesse Grosjean
See Also:
ZAlpha

Constructor Summary
ZColorAnimation(java.awt.Color aSource, java.awt.Color aDestination)
          Construct a new ZColorAnimation.
 
Method Summary
protected  void animateFrameForTime(long aTime)
          Animate one frame of this animation for the given time.
 java.awt.Color getDestinationColor()
          Return the destination color, the color that the animation will end at.
 ZFillPaint getFillPaintTarget()
          Return the fill paint target of this color animation.
 ZPenPaint getPenPaintTarget()
          Return the pen paint target of this color animation.
 java.awt.Color getSourceColor()
          Return the source color, the color that the animation will start at.
 void setDestinationColor(java.awt.Color aDestination)
          Set the destination color, the color that the animation will end at.
 void setFillPaintTarget(ZFillPaint aFillPaintTarget)
          Set the fill paint target of this color animation.
 void setPenPaintTarget(ZPenPaint aPenPaintTarget)
          Set the pen paint target of this color animation.
 void setSourceColor(java.awt.Color aSource)
          Set the source color, the color that the animation will start at.
 
Methods inherited from class edu.umd.cs.jazz.animation.ZAnimation
animationRateByElapsedFrames, animationRateByElapsedTime, animationRateByNextFrame, animationStarted, animationStopped, getAlpha, isStopped, play, scheduleNextFrame, scheduleNextFrame, setAlpha, setStartedRunnable, setStoppedRunnable, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZColorAnimation

public ZColorAnimation(java.awt.Color aSource,
                       java.awt.Color aDestination)
Construct a new ZColorAnimation.

Parameters:
aSource - the source color that the animation will start at.
aDestination - the destination color that the animation will end at.
Method Detail

getSourceColor

public java.awt.Color getSourceColor()
Return the source color, the color that the animation will start at.


setSourceColor

public void setSourceColor(java.awt.Color aSource)
Set the source color, the color that the animation will start at.


getDestinationColor

public java.awt.Color getDestinationColor()
Return the destination color, the color that the animation will end at.


setDestinationColor

public void setDestinationColor(java.awt.Color aDestination)
Set the destination color, the color that the animation will end at.


getPenPaintTarget

public ZPenPaint getPenPaintTarget()
Return the pen paint target of this color animation. This is the object who's setPenPaint method will be called for each frame of the animation.


setPenPaintTarget

public void setPenPaintTarget(ZPenPaint aPenPaintTarget)
Set the pen paint target of this color animation. This is the object who's setPenPaint method will be called for each frame of the animation.


getFillPaintTarget

public ZFillPaint getFillPaintTarget()
Return the fill paint target of this color animation. This is the object whos setFillPaint method will be called for each frame of the animation.


setFillPaintTarget

public void setFillPaintTarget(ZFillPaint aFillPaintTarget)
Set the fill paint target of this color animation. This is the object who's setFillPaint method will be called for each frame of the animation.


animateFrameForTime

protected void animateFrameForTime(long aTime)
Animate one frame of this animation for the given time. The time parameter is used to generate an alpha value, which is then used to create a color interpolated between the source and destination colors. The color is then applied to both the pen paint and fill paint targets. If the animation should only apply to one of these targets the other can safely be left as null.

Overrides:
animateFrameForTime in class ZAnimation


Copyright 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.