// forked from nitoyon's AS3で半径小さい円を描いて拡大したらつぶれていて面白い // See also: http://d.hatena.ne.jp/nitoyon/20081230/as_circle_skew package { import flash.display.Graphics; import flash.display.Sprite; public class GunyaGunya extends Sprite { protected static const CONTROLPOINT_RADIUS:Number = 1 / Math.cos(Math.PI / 8); public function GunyaGunya() { for (var i:uint=1; i<=3; i++) { // (赤)nitoyonさんオリジナルの図形。100倍に拡大された小さい円 var s:Sprite = new Sprite(); s.graphics.beginFill(0xFF0000); s.graphics.drawCircle(0, 0, 0.1 * i); s.graphics.endFill(); s.scaleX = s.scaleY = 100; s.x = 100 * i; s.y = 100; addChild(s); // (緑)drawCircleを再実装し、大きな円を描いてみる s = new Sprite(); s.graphics.beginFill(0x00FF00); drawCircle(s.graphics, 0, 0, 10 * i); s.graphics.endFill(); s.x = 100 * i; s.y = 200; addChild(s); // (青)上記の円で使われる座標を、100twips = 5pixelで丸めてみる s = new Sprite(); s.graphics.beginFill(0x0000FF); drawCircleRounded(s.graphics, 0, 0, 10 * i, 0.05 * 100); s.graphics.endFill(); s.x = 100 * i; s.y = 300; addChild(s); } } /** * flash.display.Graphics#drawCircle再実装 * コードは推測。でも合っているっぽい */ private function drawCircle(graphics:Graphics, x:Number, y:Number, radius:Number):void { var cradius:Number = radius * CONTROLPOINT_RADIUS; graphics.moveTo(x + radius, y); for (var i:uint=0; i<8; i++) { var ca:Number = (i + 0.5) / 8 * Math.PI * 2; var aa:Number = (i + 1) / 8 * Math.PI * 2; graphics.curveTo( x + Math.cos(ca) * cradius, y + Math.sin(ca) * cradius, x + Math.cos(aa) * radius, y + Math.sin(aa) * radius ); } } /** * 上記メソッドに、大きさを指定して座標を丸める処理を追加 */ private function drawCircleRounded(graphics:Graphics, x:Number, y:Number, radius:Number, roundSize:Number):void { var cradius:Number = radius * CONTROLPOINT_RADIUS; graphics.moveTo(round(x + radius, roundSize), round(y, roundSize)); for (var i:uint=0; i<8; i++) { var ca:Number = (i + 0.5) / 8 * Math.PI * 2; var aa:Number = (i + 1) / 8 * Math.PI * 2; graphics.curveTo( round(x + Math.cos(ca) * cradius, roundSize), round(y + Math.sin(ca) * cradius, roundSize), round(x + Math.cos(aa) * radius, roundSize), round(y + Math.sin(aa) * radius, roundSize) ); } } /** * 数値を丸める */ private function round(source:Number, roundSize:Number):Number { return Math.round(source / roundSize) * roundSize; } } } 「AS3で半径小さい円を描いて拡大したらつぶれていて~」の原因を検証