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

flash on 2011-1-12

Get Adobe Flash player
by yama3 12 Jan 2011
    Embed
/**
 * Copyright yama3 ( http://wonderfl.net/user/yama3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/m64i
 */

package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.display.LoaderInfo;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.system.Security;
    import flash.events.MouseEvent;
    import flash.display.StageQuality;
    
    [SWF(width=465, height=465, backgroundColor=0, frameRate=60)]
    
    public class FlashTest extends Sprite {
        private var _vertices:Vector.<Number> = new Vector.<Number>();
        private var _indices:Vector.<int> = new Vector.<int>();
        private var _uvData:Vector.<Number> = new Vector.<Number>();
        private var _pX:Vector.<Number> = new Vector.<Number>();
        private var _pY:Vector.<Number> = new Vector.<Number>();
        private var _dotList:Vector.<Dot> = new Vector.<Dot>();
        private var _bmd:BitmapData;
        private var _bm:Bitmap;
        private var _shape:Shape = new Shape();
        
        private var _loader:Loader;
        private var _req:URLRequest;
        
        private var _xLen:uint = 16;
        private var _yLen:uint = 16;
        private const _dl:uint = _yLen * _xLen;
        private const _dll:uint = _dl*2;
        private const _range:uint = 5;
       
        public function FlashTest() {
            stage.quality = StageQuality.LOW;
            Security.loadPolicyFile("http://www.digifie.jp/crossdomain.xml");
            loadImage("http://www.digifie.jp/files/test100726.jpg");          
        }
        
        private function loadImage(url:String):void {
            _loader = new Loader();
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedListener);
            _loader.load(new URLRequest(url));
        }
        private function onLoadedListener(e:Event):void {
            addChild(_shape);
            var mask:Sprite = new Sprite();
            mask.graphics.beginFill(0x0, 0);
            mask.graphics.drawRect(0, 0, stage.stageWidth - _range*2, stage.stageHeight - _range*2);
            mask.graphics.endFill();
            mask.x = mask.y = _range;
            addChild(mask);
            _shape.mask = mask;
            _bmd = new BitmapData(_loader.width, _loader.height, false, 0);
            _bmd.draw(_loader);
            for(var i:uint=0; i<_xLen; i++) {
                for(var j:uint=0; j<_xLen; j++) {
                    _uvData.push(j/(_xLen-1), i/(_yLen-1));
                    _vertices.push(_bmd.width*j/(_xLen-1), _bmd.height*i/(_yLen-1));
                    _pX.push(_bmd.width*j/(_xLen-1));
                    _pY.push(_bmd.height*i/(_yLen-1));
                    
                    if(i != (_yLen - 1) && j != (_xLen -1)) {
                        _indices.push(_xLen * i + j, _xLen * i + j + 1, _xLen * (i + 1) + j);
                        _indices.push(_xLen * i + j + 1, _xLen * (i + 1) + j, _xLen * (i + 1) + j + 1);
                    }
                }
            }
            for(i=0; i<_xLen*_yLen;i++) {
                var dot:Dot = new Dot();
                dot.x = dot.xx = _pX[i];
                dot.y = dot.yy = _pY[i];
                dot.spd = i * 20;
                _dotList.push(dot);
            }
            createTriangles(_vertices, _indices, _uvData);
            addEventListener(Event.ENTER_FRAME, moveIt);
        }
        
        private function moveIt(e:Event):void {
            for(var i:uint=0; i<_dl; i++) {
                _dotList[i].spd = (++_dotList[i].spd)%360;
                var z:Number = Math.cos(_dotList[i].spd*Math.PI/180)*_range;
                var zz:Number = Math.sin(_dotList[i].spd*Math.PI/180)*_range;
                _dotList[i].x = _dotList[i].xx+z;
                _dotList[i].y = _dotList[i].yy+zz;
            }
            update();
        }
        private function update():void {
            var nX:uint = 0;
            var nY:uint = 0;
            for(var i:uint=0; i<_dll; i++) {
                if(i%2 != 1) {
                    if(nX<_dl){
                        _vertices[i] = _dotList[nX].x;
                        nX++;
                    }
                } else {
                    if(nY<_dl) {
                        _vertices[i] = _dotList[nY].y;
                        nY++;
                    }
                }
            }
            createTriangles(_vertices, _indices, _uvData);
        }
        
        private function createTriangles(ver:Vector.<Number>, ind:Vector.<int>, uv:Vector.<Number>, cull:String = "none"):void {
            _shape.graphics.clear();
            _shape.graphics.beginBitmapFill(_bmd, null, true, true);
            _shape.graphics.drawTriangles(ver, ind, uv, cull);
            _shape.graphics.endFill();
        }
    }
}

import flash.display.Sprite;
class Dot extends Sprite {
    public var xx:int;
    public var yy:int;
    public var spd:uint;
}