1  /*
  2   *  File:  RhombusTest.java
  3   *
  4   *  Draw a rhombus
  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  
 14  public class RhombusTest extends Applet {
 15  
 16     // create a reference to a rhombus:
 17     private Rhombus rhombus;
 18     
 19     // rhombus parameters:
 20     private final int length = 20;
 21     private final double alpha = 3 * Math.PI/5;
 22     private int d, h;
 23     
 24     public void init() {
 25     
 26        // the displacement from the vertical:
 27        d = ( int ) Math.round( length * Math.cos( Math.PI - alpha ) );
 28        // the height of the rhombus:
 29        h = ( int ) Math.round( length * Math.sin( Math.PI - alpha ) );
 30        
 31     }
 32  
 33     public void paint( Graphics g ) {
 34  
 35        // local variables:
 36        int x, y;
 37        int xoffset = ( d < 0 ) ? 0: 8*d; 
 38        
 39        g.setColor( Color.magenta );
 40  
 41        // draw a checkerboard of rhombi:
 42        y = 0;
 43        for ( int i = 0; i < 8; i++ ) {
 44           x = xoffset + i * (-d); y += h;
 45           for ( int j = 0; j < 8; j++ ) {
 46              x += length;
 47              rhombus = new Rhombus( x, y, length, alpha );
 48              rhombus.draw( g );
 49           }
 50        }
 51  
 52     }
 53     
 54  }