/* * 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 m_width-1) xcounter = 0; ycounter+=m_nSpeed; if(ycounter > m_height-1) ycounter = 0; for(y=0;y= 0) && (tx < m_width)) if((ty >= 0) && (ty < 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); } }