import java.applet.*;
import java.awt.*;
import java.awt.image.*;

public class main extends Applet {

	final int 			W	 			= 320,
						H 				= 240;	
	Image				img				= null,
						mis_img			= null;
	int					img_pixels[]	= new int[W*H],
						pixels[]		= new int[W*H];
	MediaTracker		mt				= null;
	MemoryImageSource	mis				= null;
	
	public void init()
	{
		this.setBackground(Color.WHITE);
		this.setSize(W,H);
		
		mt = new MediaTracker(this);				
		img = this.getImage(this.getCodeBase(),"image.jpg");		
		mt.addImage(img,0);
		try {
			mt.waitForAll();
		} catch (InterruptedException ie) {
			System.err.println("MediaTracker : Interrupted!");
			return;
		}
		
		PixelGrabber pg = new PixelGrabber(img, 0, 0, W, H, img_pixels, 0, W);
		try {
		    pg.grabPixels();
		} catch (InterruptedException e) {
		    System.err.println("PixelGrabber : Interrupted!");
		    return;
		}
		
		double angle = 0.0;
		for (int x=0; x<W; x++)
		{
			if (angle < 359.0)			
				angle ++;
			else
				angle = 0.0;
			
			double curve = Math.sin(angle*Math.PI/180)*50;
			
			for (int y=0; y<H; y++)
			{
				int tp = (int)(curve+y)*W+x;
				if (tp < W*H && tp > -1)
					pixels[y*W+x] = img_pixels[tp];							
			}
		}
		
		mis = new MemoryImageSource(W, H, pixels, 0, W);		
	    mis_img = createImage(mis);		    		
	}	
	
	public void paint (Graphics g)
	{
		g.drawImage(mis_img,0,0,this);		
	}
}