1  /*
  2   *  File:  OctagonTest.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  
 13  public class OctagonTest extends Applet {
 14  
 15     // create a reference to an octagon:
 16     private Octagon octagon;
 17     
 18     // center of regular octagon:
 19     private int x, y;
 20     
 21     // radius of regular octagon:
 22     private int r;
 23  
 24     // number of rotations:
 25     private int n = 7;
 26     
 27     // rotation angle:
 28     private double theta = 2 * Math.PI / n;
 29  
 30     public void init() {
 31       x = y = Math.min( getSize().width, getSize().height )/2;
 32       r = x - 15;
 33     }
 34  
 35     public void paint( Graphics g ) {
 36  
 37        // instantiate a regular octagon:
 38        octagon = new Octagon( x, y, r );
 39      
 40        // rotate and draw:
 41        for ( int i = 0; i < n; i++ ) {
 42           octagon.centerRotate( theta ).draw( g );
 43        }
 44  
 45     }
 46     
 47  }