<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
 * WavesApplet.java
 *
 * Alex S.
 */

import java.applet.*;
import java.awt.*;
import java.awt.image.*;

public class waves extends Applet implements Runnable
{
    Thread t = null;
    int m_nSpeed = 10;
    Color m_bgcolor=Color.white;
    MediaTracker tracker;
    
    // double buffer stuff.
    int W, H, pix[];
    Image im;
    MemoryImageSource mis;

    int[] sin_x_table;
    int[] sin_y_table;

    Image image;
    int m_width,m_height;
    int[] pixels;

    public void init() {
    
        // init double buffer
        W = bounds().width;
        H = bounds().height;
        pix = new int[W*H];
        mis = new MemoryImageSource(W, H, pix, 0, W);
        mis.setAnimated(true);
        im = createImage(mis);
        
        // get params
        String param;
        param = getParameter("bgcolor");
        if (param != null)
            m_bgcolor = new Color(Integer.parseInt(param,16));
        param = getParameter("speed");
        if (param != null)
            m_nSpeed = Integer.valueOf(param,10).intValue();
        param = getParameter("img");
        
        // load the image
        image = getImage(getDocumentBase(),param);
        if(image == null)
            return;
            
        tracker = new MediaTracker(this);
        tracker.addImage(image, 0);
        
        // grab pixels.
        try {
            tracker.waitForID(0);
            m_width = image.getWidth(this);
            m_height = image.getHeight(this);
            pixels = new int[m_width * m_height];
            PixelGrabber pg = new PixelGrabber(image,0,0,m_width,m_height,pixels,0,m_width);
            pg.grabPixels();            
        } catch (InterruptedException e) {
            return;
        }

        // init tables.
	sin_x_table = new int[2 * m_width];
	sin_y_table = new int[2 * m_height];
        
        int i;
        for(i=0;i&lt;m_width;i++)
            sin_x_table[i] = (int)(Math.sin(i * Math.PI*2/m_width) * 10);
        for(;i&lt;m_width*2;i++)
            sin_x_table[i] = sin_x_table[i-m_width];
        for(i=0;i&lt;m_height;i++)
            sin_y_table[i] = (int)(Math.sin(i * Math.PI*2/m_height) * 10);
        for(;i&lt;m_height*2;i++)
            sin_y_table[i] = sin_y_table[i-m_height];
            setBackground(m_bgcolor);
    }

    public void start() {
        if (t == null) {
            t = new Thread(this);
            t.start();
        }
    }
    
    public void stop() {
        if (t != null) {
            t.stop();
            t = null;
        }
    }
    
    public void run() {
        int x,y,tx,ty,xcounter=0,ycounter=0;
        for (;;) {
            xcounter+=m_nSpeed;
            if(xcounter &gt; m_width-1)
                xcounter = 0;
	    ycounter+=m_nSpeed;
            if(ycounter &gt; m_height-1)
                ycounter = 0;
            for(y=0;y&lt;m_height;y++){
                for(x=0;x&lt;m_width;x++){
                    tx = x + sin_y_table[y + ycounter];
                    ty = y - sin_x_table[x + xcounter];
                    if((tx &gt;= 0) &amp;&amp; (tx &lt; m_width))
                        if((ty &gt;= 0) &amp;&amp; (ty &lt; m_height))
                            pix[ty*m_width+tx]=pixels[y*m_width+x];
                }
	    }
            mis.newPixels(0, 0, W, H, true);
            repaint();
            try {
                Thread.sleep(66);
            }catch(InterruptedException ie) { ; }
        }
    }

    public void update(Graphics g){
        g.drawImage(im,0,0,null);
    }
}


</pre></body></html>