In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: 3D Carousel

パースペクティブコレクトがかかっているかチェック。
Get Adobe Flash player
by erakan 15 Jan 2009
// forked from clockmaker's 3D Carousel
// パースペクティブコレクトがかかっているかチェック。
package
{
    import flash.display.*
    import flash.text.*
    import flash.events.*
    import flash.filters.BlurFilter;
    import flash.geom.*;

    [SWF(frameRate="90", width="465", height="465")]
    public class Main extends Sprite
    {

    var _main:Sprite = null;
    var _wrap:Sprite = null;
    var _objs:Array = [];

    public function Main()
    {
        // フォント用
        var textFormat:TextFormat = new TextFormat();
        textFormat.font  ="MS Pゴシック";
        textFormat.align = TextFormatAlign.LEFT;;
        textFormat.color = "0x000000";
        textFormat.size  = 48;
        textFormat.bold = true;

        // ワールド(?)用
        _main = Sprite(addChild(new Sprite()));
        _main.x = stage.stageWidth / 2;
        _main.y = stage.stageHeight / 2;

        // リング
        _wrap = Sprite(_main.addChild(new Sprite()));

        const NUM_POLYS:int   = 15;
        const POLY_WIDTH:int  = 100;
        const POLY_HEIGHT:int = 50;
        for (var i:int = 0; i < NUM_POLYS; i++)
        {
            // スプライト
            var sp:Sprite = Sprite(_wrap.addChild(new Sprite()));
            var g:Graphics = sp.graphics;
            g.beginFill(0xFFFFFF * Math.random());
            g.drawRect(-POLY_WIDTH/2, -POLY_HEIGHT/2, POLY_WIDTH, POLY_HEIGHT);
            sp.x = 300 * Math.sin(Math.PI * 2 * i / NUM_POLYS)
            sp.z = 300 * Math.cos(Math.PI * 2 * i / NUM_POLYS)

            g.lineStyle(1, 0x000000, 1.0);
            for (var y:int = 0; y <= 4; y++)
            {
                g.moveTo(-POLY_WIDTH/2, -POLY_HEIGHT/2 + POLY_HEIGHT * y / 4);
                g.lineTo( POLY_WIDTH/2, -POLY_HEIGHT/2 + POLY_HEIGHT * y / 4);
            }
            for (var x:int = 0; x <= 4; x++)
            {
                g.moveTo(-POLY_WIDTH/2 + POLY_WIDTH * x / 4, -POLY_HEIGHT/2);
                g.lineTo(-POLY_WIDTH/2 + POLY_WIDTH * x / 4,  POLY_HEIGHT/2);
            }
/*
            // スプライトにのせる文字
            var textField:TextField = new TextField();
            textField.defaultTextFormat = textFormat;
            textField.multiline         = true;
            textField.autoSize          = TextFieldAutoSize.CENTER;
            textField.x                 = 0;
            textField.y                 = -24;
            textField.text              = "田";
            sp.addChild(textField);
*/
            _objs.push(sp)
        }

        stage.addEventListener(Event.ENTER_FRAME, update);
    }
   
    function update(e:Event):void
    {
        // 消失点設定
        var pp:PerspectiveProjection = root.transform.perspectiveProjection; 

        pp.projectionCenter = new Point(stage.stageWidth / 2, stage.stageHeight / 2)

        // リングの回転
        _wrap.rotationY += (mouseX / stage.stageWidth * 480 - _wrap.rotationY) * 0.05

        // ワールド原点からの相対Zをスプライトに付加
        var arr:Array = []
        for (var i:int = 0; i < _objs.length; i++)
        {
            var ele:Sprite = _objs[i] as Sprite
//          ele.rotationY = -_wrap.rotationY
            var mtx:Matrix3D = ele.transform.getRelativeMatrix3D(_main)
            arr.push( { ele:ele, z:mtx.position.z } )
        }

        // Zソート
        arr.sortOn("z", Array.NUMERIC | Array.DESCENDING)

        // Z深度に応じてブラー
        for (i = 0; i < arr.length; i++)
        {
            ele = arr[i].ele as Sprite
            var z:Number = arr[i].z
            _wrap.setChildIndex(ele, i)
            var b:Number = Math.abs(z)

            // focus depth blur effect, warning, very slow:
            b = z/10
            ele.filters = (b > 2) ? [new BlurFilter(b, b, 3)] : []
        }
    }

    } // class Main

} // package