     /*----------------------- Naoki Hada ---------------------------/
    /  http://www.javacats.com      /   Home                        /
   /  e-mail:naoki@javacats.com    /  naoki@kage.net                /
  /  tel.415-813-9088#113/fax.9089/  tel&fax.415-965-1024         /
 /  Pager:415-527-8633           /  http://206.40.48.254/        /
/--------------------------------------------------------------*/
//	1997.1.8


import java.applet.Applet;
import java.awt.*;


public class MirageClick extends Applet implements Runnable {

	Color   background;
	final   int     Left = 0, Right = 1;
	int             lr = Right;
	Color	colorOfMirage = Color.orange;
	final	double  mirageX[] = { 00.00, 01.10, 04.00, 03.40, 06.50, 04.30, 04.20, 01.20, 01.35, 03.80, 04.10, 00.00 };
	final	double  mirageY[] = { 00.00, 20.75, 23.20, 18.50, 25.90, 25.20, 24.40, 22.90, 26.00, 27.60, 29.10, 28.00 };
	final	int             howMany = 12;
	double	scale = 10.0;
	double	x0 = 100.0;
	double	y0 = 300.0;
//	double	scale = 5.0;
//	double	x0 = 50.0;
//	double	y0 = 200.0;
	double	theta = 0.02;
	double	currentTheta = theta;


	Dimension d  ;

	int x[] = new int[21];
	int y[] = new int[21];
	int x1[] = new int[21];
	int y1[] = new int[21];
	int sx[] = new int[21];
	int sy[] = new int[21];
	int sx1[] = new int[21];
	int sy1[] = new int[21];

	int R,G,B;

	Thread thread;

	Image		offs   ;
	Graphics	grf ;

	int		changedFlag = 0;
	double	ax1, ax2, ay1, ay2;




public void init(){
	d=size();

	offs=createImage(d.width,d.height);
	grf =offs.getGraphics();

	R = (int) (Math.random()*200+55);
	G = (int) (Math.random()*200+55);
	B = (int) (Math.random()*200+55);


//	for (int i = 0; i <= 20 ; i++ ) {
//		x[i] = 1 + i*5;
//		y[i] = 1 + i*3;
//		x1[i] = 190 + i*5;
//		y1[i] = 100 + i*3;
//
//		sx[i] = a;
//		sy[i] = b;
//		sx1[i] = c;
//		sy1[i] = d;
//	}
	setBackground(Color.black);

	for( int i = 0; i < howMany; i++ ){
		mirageX[i] *= -1.0 * scale;
		mirageY[i] *= -1.0 * scale;
	}

}


	public void start() {
		if( thread == null ){
			thread = new Thread( this );
			thread.start();
		}
	}


    public void stop() {
        if( thread != null ){
            thread.stop();
            thread = null;
        }
    }


	public void paint( Graphics g ){
		grf.setColor( Color.black );
		grf.fillRect( 0, 0, d.width, d.height );
		grf.setColor( new Color( R, G, B ));

		grf.setColor( new Color( 50, 200, 150 ));
//		grf.drawString("Mirage Click 2 by Naoki Hada naoki@kage.net", 20,199);

//		if( Left == lr ){
//			current = Color.green;
//			grf.setColor( current );
//			grf.drawString( "Green Left", 10, 30 );
//		}else{  // Right
//			current = Color.red;
//			grf.setColor( current );
//			grf.drawString( "Orange Right", 10, 30 );
//		}
//		drawMirage( grf );

		if( 0 != changedFlag ){
			grf.setColor( new Color( 255, 255, 255 ));
			changedFlag = 0;
		}else{
			grf.setColor( colorOfMirage );
		}
		for( int i = 0; i < howMany-1; i++ ){
			ax1 = mirageX[i];        ay1 = mirageY[i];
			if( i == howMany - 1 ){
				ax2 = mirageX[0];        ay2 = mirageY[0];
			}else{
				ax2 = mirageX[i+1];      ay2 = mirageY[i+1];
			}
			grf.drawLine( (int)(( ax1*Math.sin( currentTheta )+x0)), (int)(ay1+y0),  (int)(( ax2*Math.sin(currentTheta)+x0)), (int)(ay2+y0) );
			grf.drawLine( (int)((-ax1*Math.sin( currentTheta )+x0)), (int)(ay1+y0),  (int)((-ax2*Math.sin(currentTheta)+x0)), (int)(ay2+y0) );
		}

		if( Left == lr )	currentTheta += theta;
		else				currentTheta -= theta;


		g.drawImage(offs,0,0,this);
	}


	public void update( Graphics g ){
		paint( g );
	}



	public  boolean mouseDown( Event e, int x, int y ){
		if( 0 != ( Event.META_MASK & e.modifiers )){
			lr = Right;
			colorOfMirage = Color.orange;
		}else{
			lr = Left;
			colorOfMirage = Color.green;
		}
		changedFlag = -1;
		repaint();
//    showStatus( "x=" + x +" y=" + y + " lr=" + lr + "e.modifiers = " + e.modifiers );
		return  true;
	}



    public void run() {
        Thread.currentThread().setPriority( Thread.NORM_PRIORITY );
        while( true ){
            try{
                Thread.sleep( 20 );
            }catch( InterruptedException e ){
                break;
            }
            repaint();
        }
        thread =null ;
    }


}




