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, xoffset; 23 24 public void init() { 25 26 // a prototype rhombus: 27 rhombus = new Rhombus( 0, 0, length, alpha ); 28 d = rhombus.getDisplacement(); 29 h = rhombus.getHeight(); 30 xoffset = ( d < 0 ) ? 0: 8*d; 31 32 } 33 34 public void paint( Graphics g ) { 35 36 g.setColor( Color.magenta ); 37 38 // local variables: 39 int x, y; 40 41 // draw an 8x8 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 }