1 /* 2 * File: QuadrilateralTest.java 3 * 4 * Telescoping trapezoids (or a striped truncated cone) 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.applet.Applet; 11 import java.awt.Graphics; 12 import java.awt.Point; 13 import java.awt.Color; 14 15 public class QuadrilateralTest extends Applet { 16 17 // create a reference to a quadrilateral: 18 private Quadrilateral trapezoid; 19 20 private int delta = 15; // increment 21 22 public void paint( Graphics g ) { 23 24 // initialize color: 25 Color c = Color.white; 26 27 // initialize base of the trapezoid: 28 Point p1 = new Point( 20, 180 ); 29 Point p2 = new Point( 360, 180 ); 30 31 // initialize roof to base: 32 Point q1 = new Point( p1 ); 33 Point q2 = new Point( p2 ); 34 35 // raise the roof, set the color, and fill: 36 do { 37 38 // compute the roof of the trapezoid: 39 q1.x += delta; q2.x -= delta; 40 q1.y -= delta; q2.y -= delta; 41 42 // instantiate a trapezoid: 43 trapezoid = new Quadrilateral( p1, p2, q2, q1 ); 44 45 // change color: 46 if ( c.equals( Color.white ) ) { 47 trapezoid.setColor( c = Color.black ); 48 } else { 49 trapezoid.setColor( c = Color.white ); 50 } 51 52 // fill the trapezoid: 53 trapezoid.fill( g ); 54 55 // the base of the next trapezoid is the roof of this trapezoid: 56 p1 = new Point( q1 ); p2 = new Point( q2 ); 57 58 } while ( q2.x - q1.x >= 2*delta ); 59 60 } 61 62 }