// GeneralPathDemo.java
// Demonstrates  a general path
// APPLET CODE="GeneralPathDemo" HEIGHT=600 WIDTH=800
import javax.swing.*;
//import java.awt.event.*;
import java.awt.*;
import java.awt.geom.*;

public class GeneralPathDemo extends JApplet {
	public void paint( Graphics g ) {
		// create 2D by casting g to Graphics2D
		Graphics2D g2d = ( Graphics2D ) g;

		int xPoints[ ] = { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43, 55 };
		int yPoints[ ] = { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36, 0 };

		// create a star from a series of points
		GeneralPath star = new GeneralPath( );

		// set the initial coordinate of the General Path
		star.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

		// create the star -- this does NOT draw the star
		// just uses the pairs of coordinates to define it
		for ( int k = 1; k < xPoints.length; k++ )
			star.lineTo( xPoints[ k ], yPoints[ k ] );

		// close the shape
	//	star.closePath( );

		// translate the origin to ( 200, 150 )
		g2d.translate( 200, 150 );

		// rotate around origin and draw stars in random colors
		for ( int j = 1; j <= 20; j++ ) {
			g2d.rotate( Math.PI / 10.0 );
			g2d.setColor( new Color( ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ) ) );
			g2d.fill( star );  // draw a filled star
		}

		// test for origin
		g2d.setColor( Color.black );
		g2d.fill( new RoundRectangle2D.Double( 0, 0, 1, 1, 1, 1 ) );


		// translate the origin again to ( 500, 150 )
		g2d.translate( 300, 0 );

		// rotate around origin and draw stars in random colors
		for ( int j = 1; j <= 20; j++ ) {
			g2d.rotate( Math.PI / 10.0 );
			g2d.setColor( new Color( ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ) ) );
			g2d.fill( star );  // draw a filled star
		}


		// translate the origin to ( 200, 450 )
		g2d.translate( -300, 300 );

		// rotate around origin and draw stars in random colors
		for ( int j = 1; j <= 20; j++ ) {
			g2d.rotate( Math.PI / 10.0 );
			g2d.setColor( new Color( ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ) ) );
			g2d.fill( star );  // draw a filled star
		}

		// translate the origin to ( 500, 450 )
		g2d.translate( 300, 0 );

		// rotate around origin and draw stars in random colors
		for ( int j = 1; j <= 20; j++ ) {
			g2d.rotate( Math.PI / 10.0 );
			g2d.translate( 10, -10 );
			g2d.setColor( new Color( ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ), ( int ) ( Math.random( ) * 256 ) ) );
			g2d.fill( star );  // draw a filled star
		}
	}
}