水波效果程序:
import java.awt.*;
import java.applet.applet;
public class splash extends applet implements runnable{
int xmax=112;
float[] m_height=new float[xmax];
float[] m_g=new float[xmax];
float b=1.01f;
float fweight=3;
private thread m_nami2d=null;
public boolean mousedown(event event,int i,int j){
m_height[i/4-1]+=j/2;
m_height[i/4]+=j;
m_height[i/4+1]+=j/2;
return false;
}
public void paint(graphics g){
g.setcolor(color.blue);
float f1=3f*fweight;
float f2=f1-2.0f;
m_height[0]=m_height[1];
m_height[xmax-1]=m_height[xmax-2];
float f=m_height[0];
for(int i=1;i<xmax-1;i++){
float f3=((f+f2*m_height[i]+m_height[i+1])/f1+m_g[i])/b;
f=m_height[i];
m_g[i]=f3-f;
m_height[i]=f3;
g.clearrect((i-1)*4,(int)f3-30,4,60);
g.fillrect((i-1)*4,(int)f3+30,4,60);
}
}
public void run(){
do
try{
repaint();
thread.sleep(50l);
}
catch(interruptedexception _ex){
stop();
}
while(true);
}
public void start(){
if(m_nami2d==null){
m_nami2d=new thread(this);
m_nami2d.start();
}
}
public void stop(){
if(m_nami2d!=null){
m_nami2d.stop();
m_nami2d=null;
}
}
public void update(graphics g){
paint(g);
}
}