package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    [SWF(width="360", height="320", backgroundColor="#ffffff", frameRate="10")]

    public class CenterOfGravity extends CameraFramework
    {
        public static const
            VIDEO_WIDTH:int = 320,          ///< ビデオの幅
            VIDEO_HEIGHT:int = 240,         ///< ビデオの高さ
            SCREEN_WIDTH:int = 360,         ///< 画面の幅
            SCREEN_HEIGHT:int = 320;        ///< 画面の高さ

        public function CenterOfGravity()
        {
            super( SCREEN_WIDTH, SCREEN_HEIGHT, VIDEO_WIDTH, VIDEO_HEIGHT );

            label.text = "Center Of Gravity";
            drawBgColor(0x03009C);
        }

        /// 描画処理
        public override function draw():void {

            bd.draw(bdTmp);

            /// 重心計算
            var grPoint:Point = new Point();
            var gravData:BitmapData = ColorGravity.getColorGravity(bdTmp, grPoint);

            if( gravData == null ){
                return;
            }

            /// 背景描画
            bd.draw(gravData);

            // 重心位置に丸を描く
            var s:Shape = new Shape();
            s.graphics.beginFill(0x0000ffff);         //塗り潰し色
            s.graphics.lineStyle(5, 0x000000);
            s.graphics.drawCircle(0, 0, 20);
            s.graphics.endFill();                //塗り潰し終了

            var pos:Matrix=new Matrix();
            pos.translate(grPoint.x, grPoint.y);
            bd.draw(s, pos);

        }

    }
}