import java.applet.Applet ;
import java.awt.* ;
import java.lang.Math ;
import java.util.Random ;

public class StarryApplet extends Applet {

	public void init() {
    		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		d.setSize( d.width - 7, d.height - 93 ) ;
		resize( d ) ;
	}

	public void paint( Graphics g ) {
		int nStars = 1000 ;  // number of stars in clump
		int mX = 500 ;       // mean x of clump stars
		int mY = 200 ;       // mean y of clump stars
		int rot= -45 ;        // clump rotation
		int sdX1 = 100 ;     // std. dev. of clump star (rotated) x
		int sdY1 = 20 ;      // std. dev. of clump star (rotated) y

		Color[] starColor = { 
			new Color( 0x9db4ff ), 
			new Color( 0xa2b9ff ), 
			new Color( 0xa7bcff ), 
			new Color( 0xaabfff ), 
			new Color( 0xafc3ff ), 
			new Color( 0xbaccff ), 
			new Color( 0xc0d1ff ), 
			new Color( 0xcad8ff ), 
			new Color( 0xe4e8ff ), 
			new Color( 0xedeeff ), 
			new Color( 0xfbf8ff ), 
			new Color( 0xfff9f9 ), 
			new Color( 0xfff5ec ), 
			new Color( 0xfff4e8 ), 
			new Color( 0xfff1df ), 
			new Color( 0xffebd1 ), 
			new Color( 0xffd7ae ), 
			new Color( 0xffc690 ), 
			new Color( 0xffbe7f ), 
			new Color( 0xffbb7b ), 
			new Color( 0xffbb7b ) 
		} ;

	    	Dimension d = getSize() ;
		Random r = new Random() ;

		double omega, cosOmega, sinOmega ;
		omega = rot * Math.PI / 180 ;
		cosOmega = Math.cos( omega ) ;
		sinOmega = Math.sin( omega ) ;

	    	g.setColor( Color.black ) ;
	    	g.fillRect( 0, 0, d.width, d.height ) ;
	    	
		for ( int n = 0 ; n < nStars ; n ++ ) {
			int x, y ;
			x = y = -1 ;

			while ( x < 0 || x > d.width || y < 0 || y > d.height ) {
				double x1, y1 ;
				x1 = r.nextGaussian() * sdX1 ;
				y1 = r.nextGaussian() * sdY1 ;
				x = (int) ( mX + x1 * cosOmega - y1 * sinOmega ) ;
				y = (int) ( mY + y1 * cosOmega + x1 * sinOmega ) ;
			}
	    		g.setColor( starColor[ (int) (starColor.length * r.nextDouble()) ] ) ;
			g.fillOval( x, y, 1, 1 ) ;
		}
		g.setColor( Color.cyan ) ;
		g.drawLine( 0, d.height - 3, d.width - 42, d.height - 3) ;
		g.drawString( "(ka*", d.width - 40, d.height ) ;
	}
}