forked from: 【問題】Graphics の drawCircle と drawRoundRect が壊れました

by coppieee forked from 【問題】Graphics の drawCircle と drawRoundRect が壊れました (diff: 10)
Graphics.drawCircle と drawRoundRect が壊れました。
別の方法で、半径 CIRCLE_RADIUS の 円を書きなさい。
@mxmlc -o bin/CircleTest.swf -load-config+=obj\Alltest3Config.xml
@author jc at bk-zen.com
♥0 | Line 37 | Modified 2009-12-04 01:06:04 | MIT License
play

ActionScript3 source code

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

package 
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * Graphics.drawCircle と drawRoundRect が壊れました。
	 * 別の方法で、半径 CIRCLE_RADIUS の 円を書きなさい。
	 * @mxmlc -o bin/CircleTest.swf -load-config+=obj\Alltest3Config.xml
	 * @author jc at bk-zen.com
	 */
	public class CircleTest extends Sprite
	{
		private const ANSWER_COLOR: uint = 0x003366;
		private const COLOR: uint = 0x3399CC;
		private const CIRCLE_RADIUS: Number = 50;
		
		public function CircleTest() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e: Event = null): void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			//
			var centerX: Number = (stage.stageWidth - CIRCLE_RADIUS) / 2;
			var centerY: Number = (stage.stageHeight - CIRCLE_RADIUS) / 2;
			var g: Graphics = graphics;
			// 差を見るために解答として先に半径+1 の円を描いておきます。
			g.beginFill(ANSWER_COLOR); g.drawCircle(centerX, centerY, CIRCLE_RADIUS + 1);
			
			// 
			drawCircle(g, centerX, centerY, CIRCLE_RADIUS, COLOR);
		}
		
		/**
		 * これを作る。
		 * @param	g
		 * @param	x
		 * @param	y
		 * @param	r
		 * @param	color
		 */
		public function drawCircle(g: Graphics, x: Number, y: Number, r: Number, color: uint): void
		{
			var n:int = 300;
			for (var i:int = 0; i < n; i++ )
			{
				var theta:Number = Math.PI * 2 *i/ n;
				g.lineStyle(1, color);
				g.moveTo(x, y);
				g.lineTo(x+Math.cos(theta)*r,y+Math.sin(theta)*r);
			}
		}
	}
}