/* Copyright (C) 2005 Varun Hiremath. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * @author Varun Hiremath * @version 0.1 */ import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; import java.awt.image.*; import java.util.Vector.*; public class DissolveImage extends Applet implements Runnable { String scroll_text; int x=0,y=0; volatile Thread runner; Vector imageVector = new Vector(); boolean dissolved = true; Dimension size; Image final_image; Random generate = new Random(); int w,h; int[] pixels1; int[] pixels2; int[] index; int count=0; int image_no=0; int no_of_images=0; public void init() { String param; while ((param = getParameter("image" + new Integer(no_of_images + 1).toString())) != null) { Image fig = getImage(getCodeBase(), param); imageVector.add(fig); ++no_of_images; } size = getSize(); } public void start() { w=size.width; h=size.height; pixels1 = new int[w * h]; pixels2 = new int[w * h]; runner = new Thread(this); runner.start(); } public void stop() { runner = null; } public void paint(Graphics g) { if(dissolved) { PixelGrabber pg1 = new PixelGrabber((Image)imageVector.elementAt(image_no), 0, 0, w, h, pixels1, 0, w); if((image_no+1)==(no_of_images)) image_no=-1; PixelGrabber pg2 = new PixelGrabber((Image)imageVector.elementAt(image_no+1), 0, 0, w, h, pixels2, 0, w); try { pg1.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } try { pg2.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } index = new int[w * h]; for(int i =0 ; i= w*h) { dissolved = true; count=0; image_no++; for(long k=0;k < 1e8;k++); break; } else pixels1[index[count]] = pixels2[index[count++]]; } final_image = createImage(new MemoryImageSource(w, h, pixels1, 0, w)); g.drawImage(final_image, 0, 0, this); } public void update(Graphics g) { paint(g); } public void run() { while(true) { try { Thread.sleep(20000); } catch (Exception e) { ;} repaint(); } } }