//=================================================================
//	PROJECT:            _programming.java_
//	FILE:               Wormhole.java
//	PURPOSE:            Chapter 2 lablet, third and final pass
//	VERSION:            1.0
//	TARGET:             Java v1.1 or above
//	UPDATE HISTORY:     1.0     1/20/00
//=================================================================

//---------------------------- NOTES ------------------------------
/*
    This is the "final" version of the Wormhole program, as described in
    Chapter 2 of the text.  It incorporates all of the features mentioned,
    including a method of our own to actually do the drawing.

    It works best if the applet size is set to 500 x 350.

    Notice that there is no init() method in this applet.  We
    could have included one, but it isn't necessary in this case,
    since all of our instance variables are primitve types (ints)
    and can be initialized when they are declared at the beginning
    of the class definition.
*/

//-------------------------- IMPORTS ------------------------------
/*
    These are the only two libraries we need, since there is no
    "event" handling going on here.
*/
import java.applet.*;
import java.awt.*;

//========================== Wormhole CLASS ============================
/**
 * This applet draws a scene consisting of ten nested blue ovals
 * on a black background, along with a text message.
 */
public class Wormhole extends Applet
{
	/**
	 * Do all the drawing.
	 */
	public void paint(Graphics g)
	{
		// Draw the black background.
		g.setColor(Color.black);
		g.fillRect(0, 0, 500, 350);
		
		// Draw ten nested "holes."
		drawHole(0, g);
		drawHole(1, g);
		drawHole(2, g);
		drawHole(3, g);
		drawHole(4, g);
		drawHole(5, g);
		drawHole(6, g);
		drawHole(7, g);
		drawHole(8, g);
		drawHole(9, g);
		 
		// Draw the text, in white with a blue drop shadow.
		g.setColor(Color.blue);
		g.setFont(new Font("TimesRoman", Font.BOLD, 36));
		g.drawString("On to Cydonia!", 22, 300);
		
		g.setColor(Color.white);
		g.drawString("On to Cydonia!", 20, 298);
	}
	
	/**
	 * Using the supplied Graphics object, draw the n-th hole.
	 * n should be between 0 (darkest, largest) and 9 (lightest,
	 * smallest).
	 */
	private void drawHole(int n, Graphics g)
	{
		int X0 = 50,		// x-anchor
			Y0 = 50,		// y-anchor
			W0 = 350,		// initial width
			H0 = 200,		// initial height
			X_INC = 30,		// x-anchor increment
			Y_INC = 10,		// y-anchor increment
			RG_INC = 10,	// red-green increment
			BLUE_INC = 25;	// blue increment
			
		g.setColor(new Color(n * RG_INC, n * RG_INC, (n + 1) * BLUE_INC));
		g.fillOval(X0 + n * X_INC, Y0 + n * Y_INC,
					W0 - n * X_INC, H0 - n * 2 * Y_INC);
	}
}



