forked from: pure as3 colour wheel

by lewis_c1986 forked from pure as3 colour wheel (diff: 66)
Draw Ellipse
By Lewis Cowles
Pure AS3 Very Very Fast way to create an ellipse, 
extremely fast algorithm	to use this in your own works 
you must leave the contextMenu Alone and if your 
application is commercial there will be a royalty fee
you may only use if you have my express written consent
by snailmail(standard post) or e-mail

♥0 | Line 52 | Modified 2010-04-27 05:05:59 | MIT License
play

ActionScript3 source code

/**
 * Copyright lewis_c1986 ( http://wonderfl.net/user/lewis_c1986 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iuPN
 */

/*
	Draw Ellipse
	By Lewis Cowles
	Pure AS3 Very Very Fast way to create an ellipse, 
	extremely fast algorithm	to use this in your own works 
	you must leave the contextMenu Alone and if your 
	application is commercial there will be a royalty fee
	you may only use if you have my express written consent
	by snailmail(standard post) or e-mail
	
*/
package
{
	import flash.display.*;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import flash.events.ContextMenuEvent;
	import flash.net.*;
	import flash.text.*;	
	import flash.events.*;
	public class ColorWheel extends MovieClip
	{
		public function ColorWheel(_radMax:Number = 14, _radMin:Number = 0)
		{
			//if((_radMin <= 0) || (_radMin > _radMax))
			//	_radMin = _radMax / 2;
			var menu:ContextMenu = new ContextMenu();
			menu.hideBuiltInItems();
			menu.customItems.push(new ContextMenuItem("Created By Lewis Cowles", true, true));
			menu.customItems[0].addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function():void{
				navigateToURL(new URLRequest("http://lewiscowles.blogspot.com/"), "_blank");
			});
			contextMenu = menu;
			var sprite:Sprite = new Sprite();
			//this is for wonderFL testing only
			_radMax = ( stage.stageWidth / 2 ) - 2; // take this line out when using in your own apps
			if((_radMin <= 0) || (_radMin > _radMax))
				_radMin = _radMax / 2;
			
			x += 2;
			y += 2;
			var shape:Shape = new Shape();
			var x:Number = _radMax;
			var y:Number = _radMax;
			var angleDelta:Number = Math.PI / 4;
			// While the circle has only one distance to the control point for each segment, 
			// the ellipse has two distances: one that corresponds to xRadius and another that
			// corresponds to yRadius.
			var xCtrlDist:Number = _radMin/Math.cos(angleDelta/2);
			var yCtrlDist:Number = _radMax/Math.cos(angleDelta/2);
			var rx:Number, ry:Number, ax:Number, ay:Number;
			shape.graphics.moveTo(x + _radMin, y);
			var angle:Number = 0;
			for (var i:Number = 0; i < 8; i++)
			{
				shape.graphics.lineStyle(1, 0x000000, 100);
				angle += angleDelta;
				rx = x + Math.cos(angle-(angleDelta/2))*(xCtrlDist);
				ry = y + Math.sin(angle-(angleDelta/2))*(yCtrlDist);
				ax = x + Math.cos(angle)*_radMin;
				ay = y + Math.sin(angle)*_radMax;
				shape.graphics.curveTo(rx, ry, ax, ay);
			}
			
			addChild(sprite);
			sprite.addChild(shape);
		}
	}
}