1  /**
     2   * com.sekati.draw.Oval
     3   * @version 1.0.5
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9  import com.sekati.geom.Point;
    10  
    11  /**
    12   * Oval Object
    13   */
    14  class com.sekati.draw.Oval {
    15  
    16  	private var _mc:MovieClip;
    17  	public var _center:Point;
    18  	public var _radius:Point;
    19  	public var _fc:Number;
    20  	public var _fa:Number;
    21  	public var _sw:Number;
    22  	public var _sc:Number;
    23  	public var _sa:Number;
    24  
    25  	/**
    26  	 * Oval Constructor
    27  	 * @param mc (MovieClip)
    28  	 * @param center (Point)
    29  	 * @param radius (Point)
    30  	 * @param fillColor (Number) hex fill, if undefined rectangle will not be filled
    31  	 * @param fillAlpha (Number) fill alpha transparency [default: 100]
    32  	 * @param strokeWeight (Number) line width [default: 1]
    33  	 * @param strokeColor (Number) line color [default: 0x000000]
    34  	 * @param strokeAlpha (Number) line alpha transparency [default: 100]
    35  	 * @return Void
    36  	 */
    37  	public function Oval(mc:MovieClip, center:Point, radius:Point, fillColor:Number, fillAlpha:Number, strokeWeight:Number, strokeColor:Number, strokeAlpha:Number) {
    38  		_mc = mc;
    39  		_fc = fillColor;
    40  		_fa = (isNaN( fillAlpha )) ? 100 : fillAlpha;
    41  		_sw = (!strokeWeight) ? undefined : strokeWeight;
    42  		_sc = (isNaN( strokeColor )) ? 0x000000 : strokeColor;
    43  		_sa = (isNaN( strokeAlpha )) ? 100 : strokeAlpha;
    44  		_center = center;
    45  		_radius = radius;
    46  		draw( );
    47  	}
    48  
    49  	/**
    50  	 * (Re)Draw line with current properties.
    51  	 * @return Void
    52  	 */
    53  	public function draw():Void {
    54  		_mc.clear( );
    55  		_mc.lineStyle( _sw, _sc, _sa, true, "none", "round", "round", 8 );
    56  		if (!isNaN( _fc )) {
    57  			_mc.beginFill( _fc, _fa );
    58  		}
    59  		var angleMid:Number, px:Number, py:Number, cx:Number, cy:Number;
    60  		var theta:Number = Math.PI / 4;
    61  		
    62  		// calculate the distance for the control point
    63  		var xrCtrl:Number = _radius.x / Math.cos( theta / 2 );
    64  		var yrCtrl:Number = _radius.y / Math.cos( theta / 2 );
    65  		
    66  		// start on the right side of the circle
    67  		var angle:Number = 0;
    68  		_mc.moveTo( _center.x + _radius.x, _center.y );
    69  		
    70  		// this loop draws the circle in 8 segments
    71  		for (var i:Number = 0; i < 8 ; i++) {
    72  			// increment our angles
    73  			angle += theta;
    74  			angleMid = angle - (theta / 2);
    75  			
    76  			// calculate our control point
    77  			cx = _center.x + Math.cos( angleMid ) * xrCtrl;
    78  			cy = _center.y + Math.sin( angleMid ) * yrCtrl;
    79  			
    80  			// calculate our end point
    81  			px = _center.x + Math.cos( angle ) * _radius.x;
    82  			py = _center.y + Math.sin( angle ) * _radius.y;
    83  			
    84  			// draw the circle segment
    85  			_mc.curveTo( cx, cy, px, py );
    86  		}
    87  		if (!isNaN( _fc )) {	
    88  			_mc.endFill( );
    89  		}	
    90  	}
    91  }