// applet "Melts an Image" // needs import java.applet.* ; import java.awt.image.* ; import java.awt.Image ; import java.awt.image.PixelGrabber; import java.awt.MediaTracker ; import java.awt.image.MemoryImageSource ; import java.awt.Graphics ; public final class Melting extends Applet implements Runnable { static String message = "...courtesy Taylor Computing (http://taylor.digex.net)"; private Thread melting_thread = null; private AudioClip audio_clip = null; private Image base_image, melting_image; private int melt_yoffset=0; public void init() { MediaTracker tracker = new MediaTracker(this); String audio_file; // who showStatus(message); // base_image base_image = getImage(getDocumentBase(), getParameter("img")); tracker.addImage(base_image, 0); melting_image = base_image; // who showStatus(message); // load it all before continuing try { tracker.waitForAll(); } catch (InterruptedException e){} ; // audio audio_file = getParameter("audio"); if ( audio_file != null ) { audio_clip = getAudioClip( getDocumentBase(), audio_file); } // who showStatus(message); } public void paint(Graphics g) { g.drawImage(melting_image, 0, melt_yoffset, this); } public void run() { int mstep_i,mstep_n=8,mstep_height; int image_width, image_height; int image_pixels[]; Image melting_images[]; image_width = base_image.getWidth(this); image_height = base_image.getHeight(this); image_pixels = new int[image_width * image_height]; //# Create a PixelGrabber to Get the Pixels of the image and store //# them into the image_pixels array PixelGrabber pixel_grabber = new PixelGrabber(base_image.getSource(), 0, 0, image_width, image_height, image_pixels, 0, image_width); try { pixel_grabber.grabPixels(); } catch (InterruptedException e) {;} pixel_grabber = null; repaint(0); // copy the base // base_copy = new LoadImage(base_image); // "melt the image" melting_images = new Image[mstep_n]; mstep_height = image_height/mstep_n; // first is base...make the rest { melting_images[0] = base_image; for(mstep_i=1; mstep_i= image_height) from_y = image_height - 1; for(to_x=0;to_x= image_width) from_x = image_width - 1; to_pixels[to_index] = image_pixels[ (from_y * image_width) + from_x]; }// end for x }// end for y } // make it melting_images[mstep_i] = createImage( new MemoryImageSource(image_width,to_height,to_pixels,0,image_width)); // don't need to_pixels = null; // make it real // prepareImage(melting_images[mstep_i]); } } } // gc just for fun Runtime.getRuntime().gc(); // loop every ??sec up/down try { melting_thread.sleep(5*1000) ; } catch(InterruptedException e){} ; while( true ) { // play audio if you have some if (audio_clip != null) { audio_clip.play(); try { melting_thread.sleep(1*1000) ; } catch(InterruptedException e){} ; } // melt for(mstep_i=1;mstep_i-1;mstep_i--) { melting_image = melting_images[mstep_i]; melt_yoffset -= mstep_height; repaint(0); try { melting_thread.sleep(300) ; } catch(InterruptedException e){} ; }// end for // who showStatus("Better."); try { melting_thread.sleep(10*1000) ; } catch(InterruptedException e){} ; }// end while } public void start() { if (melting_thread == null) { melting_thread = new Thread(this); melting_thread.start(); } // who showStatus(message); } public void stop() { melting_thread.stop(); melting_thread = null; // who showStatus(message); } } // end Melting
Make your own free website on Tripod.com