Professional Documents
Culture Documents
* Name: Water
* Date: December 2004
* Author: Neil Wallis
* Purpose: Simulate ripples on water.
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.applet.Applet;
import java.net.URL;
public class water extends Applet implements
Runnable, MouseListener, MouseMotionListener {
String str;
int width,height,hwidth,hheight;
MemoryImageSource source;
Image image, offImage;
Graphics offGraphics;
int i,a,b;
int MouseX,MouseY;
int fps,delay,size;
short ripplemap[];
int texture[];
int ripple[];
int oldind,newind,mapind;
int riprad;
Image im;
Thread animatorThread;
boolean frozen = false;
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
//Retrieve the base image
str = getParameter("image");
if (str != null) {
try {
MediaTracker mt = new MediaTracker(this);
im = getImage(getDocumentBase(),str);
mt.addImage(im,0);
try {
mt.waitForID(0);
} catch (InterruptedException e) {
return;
}
} catch(Exception e) {}
}
//How many milliseconds between frames?
str = getParameter("fps");
try {
if (str != null) {
fps = (int)Integer.parseInt(str);
}
} catch (Exception e) {}
delay = (fps > 0) ? (1000 / fps) : 100;
width = im.getWidth(this);
height = im.getHeight(this);
hwidth = width>>1;
hheight = height>>1;
riprad=3;
size = width * (height+2) * 2;
ripplemap = new short[size];
ripple = new int[width*height];
texture = new int[width*height];
oldind = width;
newind = width * (height+3);
PixelGrabber pg = new PixelGrabber(im,0,0,width,height,texture,0,width);
try {
pg.grabPixels();
} catch (InterruptedException e) {}