forked from: 【問題】Graphics の drawCircle と drawRoundRect が壊れました
forked from 【問題】Graphics の drawCircle と drawRoundRect が壊れました (diff: 32)
Graphics.drawCircle と drawRoundRect が壊れました。 別の方法で、半径 CIRCLE_RADIUS の 円を書きなさい。 @mxmlc -o bin/CircleTest.swf -load-config+=obj\Alltest3Config.xml @author jc at bk-zen.com
ActionScript3 source code
/**
* Copyright paq ( http://wonderfl.net/user/paq )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9sPw
*/
// forked from bkzen's 【問題】Graphics の drawCircle と drawRoundRect が壊れました
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
{
function drawpoint(x:Number,y:Number):void
{
g.drawRect(x, y, 1, 1);
}
var F:Number = -2 * r + 3;
var x0:Number = x;
var y0:Number = y;
x = r;
y = 0;
g.beginFill(color)
while ( x >= y )
{
drawpoint( x0 + x, y0 + y);
drawpoint( x0 - x, y0 + y);
drawpoint( x0 + x, y0 - y);
drawpoint( x0 - x, y0 - y);
drawpoint( x0 + y, y0 + x);
drawpoint( x0 - y, y0 + x);
drawpoint( x0 + y, y0 - x);
drawpoint( x0 - y, y0 - x);
if ( F >= 0 )
{
x--;
F -= 4 * x;
}
y++;
F += 4 * y + 2;
}
}
}
}