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

AlphabetBlock

@author dubfrog aka 'dubflash' /* 

project [ AlphabetBlock ]
Get Adobe Flash player
by dubfrog 03 Sep 2010
/**
 * Copyright dubfrog ( http://wonderfl.net/user/dubfrog )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/m5od
 */

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import flash.geom.*;
    
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.materials.BitmapWireframeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.stats.StatsView;
    
    import caurina.transitions.*;
    import caurina.transitions.properties.*;
    
    /* @author dubfrog aka 'dubflash' /* 
    
    /* project [ AlphabetBlock ] */ 
    
    [SWF (width="465", height="465", backgroundColor="0")]
    
    public class Main extends BasicView 
    {
        public function Main():void 
        {
            
            engine = new Sprite();
            
            t1 = new TextField();
            t1.textColor = 0xffffff;
            t1.y = 445;
            addChild(t1);
            
            t2 = new TextField();
            t2.wordWrap = false;
            t2.textColor = 0xffffff;
            t2.autoSize = TextFieldAutoSize.LEFT;
            
            datas = { point:new Array(), 
                      cube:new Array(), 
                      cubeMax:new Array() };
            nowNum = -1;
            cacheNum = 0;
            scale = 30;
            pixelMax = 30;
            word = "新宿";
            
            super(0, 0, true, true);
            
            var bitmap:Bitmap = new Bitmap(new BitmapData(465,465,false,0x000000));
            addChild(bitmap);
            
            Wonderfl.capture_delay(1);
            
            createWorld();
            wordDetail();
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDirect);
            engine.addEventListener(Event.ENTER_FRAME, update);
        }
        
        private function createWorld():void 
        {
            rootNode = new DisplayObject3D();
            addChild(viewport);
            camera.z = -(camera.zoom * camera.focus);
            scene.addChild(rootNode);
            
            //stats表示
            var stats:StatsView = new StatsView(renderer);
            addChild(stats);
            
            rootNode.scale = scale;//スケール調整
            startRendering();
        }
        
        private function wordDetail():void
        {
            nowNum++;
            t1.text = "selected : [ "+word + " ]";
            t2.text = word;
            extra = { tw:t2.width, th:t2.height };
            colorNum = 0xffffffff * Math.random();
            
            var bmp:BitmapData = new BitmapData(t2.width, t2.height, true, 0x808080);
            bmp.draw(t2);
            var bmpObj:Bitmap = new Bitmap(bmp);
            var cnt:Number = 0;
            for (var w:Number = 0; w <= t2.width; w++) 
            {
                for (var h:Number = 0; h <= t2.height; h++)
                {
                    var dotColor:String = bmp.getPixel(w, h).toString(16);
                    if (dotColor == "ffffff")
                    {
                        datas.point[cnt] = new Point(w, h);
                        cnt++;
                    }
                }
            }
            
            datas.cubeMax.push(cnt-1);//push
            addPixels();
        }
        
        private function addPixels():void
        {
            datas.cube.push(new Array());
            for (var i:Number = 0; i <= datas.cubeMax[datas.cubeMax.length - 1]; i++)
            {
                addCubic(i);
            }
        }
        
        private function addCubic(n:Number):void 
        {
            var mat:BitmapWireframeMaterial = new BitmapWireframeMaterial(0xffffff, .5, 3);
            var c_cube:Cube = new Cube(new MaterialsList( { all:mat } ), 1, 1, 1, 1, 1, 1);
            var gx:Number = datas.point[n].x - extra.tw / 2;
            var gy:Number = -(datas.point[n].y ) + extra.th / 2;
            var gz:Number = 0;
            
            c_cube.x = gx + (Math.random() * 4 - 2);
            c_cube.y = gy + (Math.random() * 4 - 2);
            c_cube.z = gz + (Math.random() * 4 - 2);
            
            c_cube.useOwnContainer = true;
            rootNode.addChild(c_cube);
            datas.cube[datas.cube.length - 1][n] = c_cube;//push
            Tweener.addTween(c_cube, { x:gx, y:gy, z:gz, scale:1, time:1, transition:"easeOutElastic" } );
        }
        
        private function explosion():void 
        {
            var rx:Number, ry:Number, rz:Number;
            for (var i:Number = 0; i <= datas.cubeMax[cacheNum]; i++)
            {
                rx = (Math.random() * 5 - 2.5) + datas.cube[cacheNum][i].x;
                ry = (Math.random() * 5 - 2.5) + datas.cube[cacheNum][i].y;
                rz = (Math.random() * 5 - 2.5) + datas.cube[cacheNum][i].z;
                Tweener.addTween(datas.cube[cacheNum][i], { x:rx, y:ry, z:rz, alpha:0, time:1, transition:"easeOutQuard" } );
            }
            
            Tweener.addCaller(this, { time:1, count:1, onComplete:remove, onCompleteParams:[cacheNum] } );
            cacheNum = nowNum;
        }
        
        private function remove(n:Number):void
        {
            for (var i:Number = 0; i <= datas.cubeMax[n]; i++) 
            {
                Tweener.removeTweens(datas.cube[n][i]);
                rootNode.removeChild(datas.cube[n][i]);
            }
        }
        
        private function reset():void
        {
            datas.point = [];
            extra = null;
        }
        
        private function keyDirect(e:KeyboardEvent):void 
        {
            word = String.fromCharCode(e.keyCode);
            reset();
            wordDetail();
            explosion();
        }
        
        private function update(e:Event):void 
        {
            rootNode.rotationX -= .5;
            rootNode.rotationY += .6;
            rootNode.rotationZ += 1.3;
        }
        
        /*_Vars______________________________________________________________________________________*/
        
        private var word:String;
        private var engine:Sprite;
        private var rootNode:DisplayObject3D;
        private var scale:Number;
        private var extra:Object;
        private var datas:Object;
        private var colorNum:Number;
        private var pixelMax:Number;
        private var nowNum:Number;
        private var cacheNum:Number;
        private var t1:TextField;
        private var t2:TextField;
    }
}