Important alert: (current site time 7/15/2013 12:19:50 PM EDT)
 

VB icon

FLOOD PICS

Email
Submitted on: 1/30/2001 10:16:01 PM
By: Mike McNaughton  
Level: Intermediate
User Rating: By 1 Users
Compatibility: JavaScript
Views: 6637
(About the author)
 
     It slowly reveal a pic. Another cool Applet... VOTE 4 ME!!! THANX!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: FLOOD PICS
' Description:It slowly reveal a pic. Another cool Applet... VOTE 4 ME!!! THANX!
' By: Mike McNaughton
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2088&lngWId=14'for details.'**************************************

<applet code="FloodPicz.class" name="FloodPicz" width="140" height="190">
 <param name="image_ext" value="gif">
 <param name="image_num" value="5">
 <param name="image_pre" value="wow">
</applet>
<------OTHER------->
<------OTHER------->
<------OTHER------->
<------OTHER------->
<------OTHER------->
import java.applet.*;
import java.awt.*;
import java.awt.image.PixelGrabber;
import java.awt.image.MemoryImageSource;
public class FloodPicz extends Applet implements Runnable
{
	private Thread	 m_FloodPicz = null;
	boolean asodreadisegna = false;
	int piccyonshow = 0;
	int nowonshow = 0;
	int extent_x = 0;
	int extent_y = 0;
	Color coloresfondo = new Color(0,0,0);
	Color colorefont = new Color(255,255,255);
	Font graphchar = new Font("Arial", Font.BOLD, 24);
	
	//Immagine in memoria
	private int screenPixel[], memimagepix[];
	private int tile[];
	private MemoryImageSource screenMem;
private Image screenScr;
	private Graphics m_g;
	private Image globalimagedata[];
	int pic_num = 0;
	
	public void init()
	{
		
		String file_prefix = getParameter("image_pre");
		String file_extens = getParameter("image_ext");
		pic_num = Integer.parseInt(getParameter("image_num"));		
		
		globalimagedata = new Image[pic_num + 1];
		int piccycount;
		MediaTracker tracker = new MediaTracker(this);
		for(piccycount = 0; piccycount < pic_num; piccycount++)
		{
			//globalimagedata[piccycount] = getImage(getDocumentBase(), getParameter("image_pre"));
			globalimagedata[piccycount] = getImage(getDocumentBase(), 
										 file_prefix + (piccycount + 1) + "." + file_extens);
			try 
			{
				tracker.waitForID(piccycount); 
			}
			catch(Exception e) {};
			tracker.addImage(globalimagedata[piccycount], piccycount);
		}
	
		// WHAT'S THIS!?!??!
		while ( (extent_x=globalimagedata[0].getWidth(this)) < 0 )						
			try { Thread.sleep(100); } catch( InterruptedException e ) {}	
		while ( (extent_y=globalimagedata[0].getHeight(this)) < 0 )						
			try { Thread.sleep(100); } catch( InterruptedException e ) {}		
		screenPixel = new int[extent_x * extent_y];
		memimagepix = new int[extent_x * extent_y];
		loadPix( piccyonshow );
		screenScr = createImage(extent_x, extent_y);
		m_g = screenScr.getGraphics();
		asodreadisegna = false;
	}
	public void update(Graphics g)
	{
		if(asodreadisegna)
			return;
		if(nowonshow == 0)
			return;
		Image TMPscreenScr = createImage( new MemoryImageSource(extent_x, 
													extent_y, 
													screenPixel, 
													0, 
													extent_x) );
		m_g.setColor ( coloresfondo );
		m_g.fillRect(0,0, extent_x , extent_y);
		m_g.drawImage(TMPscreenScr, 0, 0, this);
		//m_g.drawString("Now:" + nowonshow, 10, 20);
		paint(g);
	}
	public void paint(Graphics g)
	{
		
if (screenScr != null)
{
g.drawImage(screenScr, 0, 0, this);
}
	}
	public void start()
	{
		if (m_FloodPicz == null)
		{
			m_FloodPicz = new Thread(this);
			m_FloodPicz.start();
		}
	}
	
	public void stop()
	{
		if (m_FloodPicz != null)
		{
			m_FloodPicz.stop();
			m_FloodPicz = null;
		}
	}
	public void run()
	{
		while (true)
		{
			try
			{
				if (!asodreadisegna)
				{
					asodreadisegna = true;
					DrawSine();
					if (!asodreadisegna)
					{
						repaint();
						Thread.sleep(50);
					}
					else
					{
						Thread.sleep(9000);
					}
				}
				else
				{
					Thread.sleep(9000);
				}
			}
			catch (InterruptedException e)
			{
				stop();
			}
		}
	}
	private void DrawSine()
	{
		int punto = nowonshow * extent_x;
		asodreadisegna = true;
		for(int loopy = nowonshow; loopy <= extent_y-1 ; loopy++)
		{
			for(int loopx = 0; loopx <= extent_x-1; loopx++)	
			{
				screenPixel[punto++] = memimagepix [loopx + nowonshow * extent_x];
			}
		}
		asodreadisegna = false;
		nowonshow++;
		if (nowonshow > extent_y -1 )
		{
			nowonshow = 0;
			piccyonshow++;
			if ( piccyonshow > pic_num - 1)
			{
				 piccyonshow = 0;
			}
			loadPix (piccyonshow);
		}
	}
	private void loadPix(int picnum)
	{
		asodreadisegna = true;
		PixelGrabber grabber = new PixelGrabber( globalimagedata[picnum], 
												 0, 
												 0, 
												 extent_x, 
												 extent_y, 
												 screenPixel, 
												 0, 
												 extent_x);
		boolean done = false;
		do
		{
			try 
			{ 
				done = grabber.grabPixels( 500 ); 
			} 
			catch ( InterruptedException e ) {}
		}
		while( !done );
		grabber = new PixelGrabber( globalimagedata[picnum], 
									0, 
									0, 
									extent_x, 
									extent_y, 
									memimagepix, 
									0, 
									extent_x);
		done = false;
		do
		{
			try 
			{ 
				done = grabber.grabPixels( 500 ); 
			} 
			catch ( InterruptedException e ) {}
		}
		while( !done );
		
		asodreadisegna = false;
	}
}


Other 15 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.