1  /*
  2   *  File:  MyPolygonTest1.java
  3   *
  4   *  Rotate a regular octagon
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Graphics;
 12  import java.awt.Color;
 13  import java.awt.Point;
 14  
 15  public class MyPolygonTest1 extends Applet {
 16  
 17     // create a reference to an octagon:
 18     private Octagon octagon;
 19     
 20     // create references to eight points:
 21     private Point p1, p2, p3, p4, p5, p6, p7, p8;
 22     
 23     public void init() {
 24     
 25        // instantiate eight points (the vertices of a regular octagon):
 26        p1 = new Point( 269, 225 );
 27        p2 = new Point( 331, 225 );
 28        p3 = new Point( 375, 269 );
 29        p4 = new Point( 375, 331 );
 30        p5 = new Point( 331, 375 );
 31        p6 = new Point( 269, 375 );
 32        p7 = new Point( 225, 331 );
 33        p8 = new Point( 225, 269 );
 34        
 35        // instantiate a regular octagon:
 36        octagon = new Octagon( p1, p2, p3, p4, p5, p6, p7, p8 );
 37        
 38     }
 39     
 40     public void paint( Graphics g ) {
 41  
 42        // fill the octagon:
 43        g.setColor( Color.red );
 44        octagon.fill( g );
 45  
 46        // rotate and fill the octagon:
 47        octagon.rotate( Math.PI/2 ).fill( g );
 48        g.setColor( Color.yellow );
 49        octagon.rotate( Math.PI/2 ).fill( g );
 50        octagon.rotate( Math.PI/2 ).fill( g );
 51  
 52     }
 53     
 54  }
 55  
 56