ModernJava
http://www.modernminds.com
R ipple (Version 1.1)

Ripple is a Canvas subclass that uses a mathematical distortion algorithm to create a water-like ripple or wave animation. The ripple animation frames are rendered using a user specified background image. Each frame of animation can optionally be overlaid with a static transparent GIF (GIF89a) foreground image.

The following documentation describes how the Ripple canvas class is used. Also available is RippleApplet which can be used to plug the animation directly into a web page. The RippleApplet class is documented separately.
O peration

On initialization, Ripple loads the image to animate and the static overlay image (if specified). The code then begins to render the animation while displaying a progress bar.

Precisely how the animation is rendered and the speed at which the animation is displayed is controlled by parameters specified in the constructor and by public methods, all of which are described in detail below.
S ample

No Java Support If your browser supports Java, you should see a demonstration of the RippleApplet to the left of this text.

For this example, a picture of water was used as the background image.
C onstructors

This is the standard constructor with all possible parameters.

public Ripple(
   URL base, String image, String imageMask,
   boolean initImage, int frames, int nWaves,
   int percent, int offset, int direction,
   int delay, boolean randomize
)

This constructor allows images to be passed directly, rather than passing a URL and requiring the Ripple canvas to handle loading the images.

public Ripple(
   Image image, Image imageMask,
   boolean initImage, int frames, int nWaves,
   int percent, int offset, int direction,
   int delay, boolean randomize
)

The following is a basic constructor, requiring only image loading information. The remaining parameters are set to the default values listed below the constructor.

public Ripple(
   URL base, String image, String imageMask
)

initImage = true, frames = 0, nWaves = 10,
percent = 10, offset = 5, direction=1,
delay = 100, randomize = false

The constructor parameters are defined as follows:

URL base The base directory for locating the image files.
String image The file name of the GIF or JPEG image that is to be animated.

The file path is based starting with the directory specified by the base parameter.
String imageMask The file name of a transparent GIF (GIF89a format) image that will be drawn on top of each rendered frame. (The animated image is overlaid with the non-animated imageMask image.)

The file path is based starting with the directory specified by the base parameter.
boolean initImage If set to "true", then the applet will draw the original image and then the imageMask overlay (if specified) before the frame rendering process begins. This prevents having a blank "hole" while the rendering process is executing.

If set to "false", then only a progress bar at the bottom of the applet will be displayed.
int frames The number of frames of animation to create.

The more frames of animation that are created, the smoother the animation will be, but the longer the initialization time will be.
int nWaves The number of vertical sine waveforms to use when creating "ripples."
int percent This parameter specifies the amplitude of each sine wave in percent of image height.
int offset The incremental number of degrees of offset that should be used for the sine waves when generating each frame of animation (must be between 0 and 360 degrees).
int direction This parameter controls the direction of the ripple movement.

If set to 1, then the ripples will move from the bottom to the top. If set to 2, then the ripples will move from the top to the bottom.
int delay The number of milliseconds to delay between each frame of the "ripple" animation.

This parameter determines the speed of the animation.
boolean randomize If set to "true", then a small amount of randomness is introduced into the wave amplitude when each frame is rendered.
P ublic Methods

This section lists the methods that can be called from a Java program to control or alter the animation.


public void start()

Starts the animation.

public void stop()

Stops the animation.

public void setFrames(int nbrFrames)

Sets the number of frames of animation to render.

If the animation is active and if nbrFrames is not equal to the current number of frames in the animation, then the animation will be stopped, re-rendered, then started again.


public void setWaves(int nbrWaves)

Sets the number of sine waveforms used to create the "ripple" effect for each frame of animation.

If the animation is active, then the animation will be stopped, re-rendered, then started again.


public void setPercent(int modulationPercent)

Sets the wave amplitude in percent of image height for the sine waveforms.

If the animation is active, then the animation will be stopped, re-rendered, then started again.


public void setOffset(int waveOffsetDegrees)

Sets the incremental number of degrees of offset that should be used for the sine waves when generating each frame of animation.

If the animation is active, then the animation will be stopped, re-rendered, then started again.


public void setDirection(int direction)

Sets the direction of the ripple movement. If set to 1, then the ripples will move from the bottom to the top. If set to 2, then the ripples will move from the top to the bottom.

public void setDelay(int frameDelay)

Sets the number of milliseconds to delay between each frame of the "ripple" animation.

public void setRandomizer(boolean randomizeAnimation)

If set to "true", then a small amount of randomness is introduced into the wave amplitude when each frame is rendered.

If the animation is active, and if the randomizeAnimation state has changed, then the animation will be stopped, re-rendered, then started again.
D ownload

The class file for Ripple, along with a copy of this documentation, is available for download as a standard zip file, as a self-extracting file (for Windows95/NT users), or as a slef-installing Java class file.
C opyright

This documentation and the object code for RippleApplet and Ripple may be copied and distributed freely for non-commercial purposes so long as neither the code nor the documentation is altered in any way. If the object code is distributed with any documentation whatsoever, then this unaltered document must accompany the code.


Copyright © 1997, 1998 by Modern Minds, Inc.