四角を敷き詰める。

by meika_kouri
♥0 | Line 34 | Modified 2010-09-23 11:01:07 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var squeres:Vector.<Shape> = new Vector.<Shape>();
            var line:Number = 60;
            var centerX:Number = stage.stageWidth / 2;
            var centerY:Number = stage.stageHeight / 2;
            
            //同じ四角をVectorに入れて位置をずらす
            for(var i:uint = 0; i < 3; i++){
                for(var j:uint = 0; j < 3; j++){
                    var nowIndex:uint = i * 3 + j; //左上から横優先
                    squeres[nowIndex] = drawSquere(line);
                    //画面中央基準なのでカウンタから1引く
                    squeres[nowIndex].x = centerX + (j - 1) * (line + 5); 
                    squeres[nowIndex].y = centerY + (i - 1) * (line + 5);
                    addChild(squeres[nowIndex]);
                }

            }

         }
        
        //中央を基準点にした四角Shape。
        private function drawSquere(line:Number):Shape{
            var harfLine:Number = line / 2;
            var squere:Shape = new Shape();
            var g:Graphics = squere.graphics;
            g.beginFill(0x00FFFF);
            g.moveTo(-harfLine, -harfLine);
            g.lineTo(harfLine, -harfLine);
            g.lineTo(harfLine, harfLine);
            g.lineTo(-harfLine, harfLine);
            g.lineTo(-harfLine, -harfLine);
            
            return squere;
                    }

    }
}