001    package fang;
002    
003    import java.awt.geom.Arc2D;
004    
005    
006    /**
007     * This class represents a circular arc as a Sprite.
008     * 
009     * This arc is defined as part of a full oval by a 
010     * start and end angle around the oval. The angles 
011     * are specified such that 45 degrees falls halfway
012     * up between the width and height ratio of the oval.
013     * The arc sweeps around counter-clockwise from the 
014     * start angle to the end angle.  For example, given
015     * 0 and 180 as the start and end angles, defines an 
016     * arc over the top half of the oval; but given 180 
017     * and 0 as the start and end angles, defines an arc 
018     * over the bottom half of the oval.
019     * 
020     * The arc is enclosed by drawing a straight line from 
021     * the start of the arc segment to the end of the arc 
022     * segment.
023     * 
024     * @author Robert Duvall
025     */
026    public class ArcSprite extends Sprite
027    {
028        /**
029         * Makes a Sprite that looks like a circular arc,
030         * i.e., its width and height ratio is 1:1,
031         * that goes from the given start angle to the
032         * given end angle.
033         * 
034         * @param start beginning angle in degrees of the arc
035         * @param end ending angle in degrees of the arc
036         */
037        public ArcSprite (double start, double end)
038        {
039            this(1, 1, start, end);
040        }
041    
042    
043        /**
044         * Makes a Sprite that looks like an arc 
045         * that goes from the given start angle to the
046         * given end angle, on an oval proportioned 
047         * according to the given width and height 
048         * ratio.
049         * 
050         * The magnitude of the width and height only 
051         * matter with respect to each other. For example, 
052         * a Sprite constructed with a width 2 and height 
053         * 1 is the same as making the width 20 and the 
054         * height 10 because they both have the same 
055         * height/width aspect ratio of 2.
056         * 
057         * @param width width scale of the rectangle
058         * @param height height scale of the rectangle
059         * @param start beginning angle in degrees of the arc
060         * @param end ending angle in degrees of the arc
061         */
062        public ArcSprite (double width, double height, double start, double end)
063        {
064            Arc2D.Double arc = new Arc2D.Double(0, 0, width, height,
065                                                start, (end > start) ? end - start : (360 + end) - start,
066                                                Arc2D.OPEN);
067            setAbsoluteShape(arc);
068        }
069    }