001package horstmann.ch06_scene3;
002import java.awt.geom.Line2D;
003import java.awt.geom.Point2D;
004import java.awt.geom.Rectangle2D;
005
006/**
007   A house shape.
008 */
009public class HouseShape extends CompoundShape
010{
011        /**
012      Constructs a house shape.
013      @param x the left of the bounding rectangle
014      @param y the top of the bounding rectangle
015      @param width the width of the bounding rectangle
016         */
017        public HouseShape(int x, int y, int width)
018        {
019                Rectangle2D.Double base
020                = new Rectangle2D.Double(x, y + width, width, width);
021
022                // The left bottom of the roof
023                Point2D.Double r1
024                = new Point2D.Double(x, y + width);
025                // The top of the roof
026                Point2D.Double r2
027                = new Point2D.Double(x + width / 2, y);
028                // The right bottom of the roof
029                Point2D.Double r3
030                = new Point2D.Double(x + width, y + width);
031
032                Line2D.Double roofLeft
033                = new Line2D.Double(r1, r2);
034                Line2D.Double roofRight
035                = new Line2D.Double(r2, r3);
036
037                add(base);
038                add(roofLeft);
039                add(roofRight);
040        }
041}