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 2014-10-31

@author Javid
Get Adobe Flash player
by J.J 31 Oct 2014
    Embed
/**
 * Copyright J.J ( http://wonderfl.net/user/J.J )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/x2kg
 */

package {
    import flash.system.LoaderContext;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.display.Sprite;
    /**

     * @author Javid

     */
    public class Main2 extends Sprite {

        private var loader : Loader;
        private var bmp : Bitmap;
        private var canvas : Bitmap;
        private var h : int;
        private var w : int;
        private var r:Number;
        private var ps:Vector.<P>;
        private const sefid : uint = 0xffffff;
        private var len : uint;
        public function Main2() {
            w=stage.stageWidth;
            h=stage.stageHeight;
            r=w/2;
            loader=new Loader()
            loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/9/90/9073/9073c8512949230e98654b31cc9cc49aefb7bd1c"),new LoaderContext(true))
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, comp)
            canvas=new Bitmap()
            canvas.bitmapData=new BitmapData(w, h,false)                        
        }
        private function comp(e : Event) : void {
            bmp=e.target.content as Bitmap;
            trace("sds");
            //this.addChild(bmp)
            ps=new Vector.<P>();            
            threshold(0xffffff/15);
            len=ps.length
            this.addChild(canvas)
       this.addEventListener(Event.ENTER_FRAME, loop)        
        }
        private function loop(event : Event) : void {
            canvas.bitmapData.lock()
            render();
            canvas.bitmapData.unlock();
        }
        private function render():void{
            var cn:BitmapData=canvas.bitmapData;
            cn.fillRect(cn.rect, sefid)
            for (var i : int = 0; i < len; i++) {
                var p:P=ps[i];
                var ax:Number=p.tx-p.x;
                var ay:Number=p.ty-p.y;
                ax*=.05;
                ay*=.05;
                p.vx=ax;
                p.vy=ay;
                var l:Number=Math.sqrt(ax*ax+ay*ay);
                if(l<.001){
                    if(!p.flag){
                    p.vx=0;
                    p.vy=0;
                    p.tx=p.fx;
                    p.ty=p.fy;
                    p.flag=!p.flag;
                    
                    }else{
                    p.tx=p.trgx;
                    p.ty=p.trgy;
                    p.flag=!p.flag;          
                    }
                }
                p.ax+=p.vx;
                p.ay+=p.vy;
                p.x+=p.vx;
                p.y+=p.vy;
                p.vx*=.6;
                p.vy*=.6;
                cn.setPixel(p.x, p.y, 0)
                cn.setPixel(p.x+p.vx, p.y+p.vy, 0)
            }
       
        }
        private function threshold(t:uint,color:uint=0):void{
            var cn:BitmapData=canvas.bitmapData;
            var bn:BitmapData=bmp.bitmapData;
            for (var i : int = 0; i <w; i++) {
                for (var j : int = 0; j < h; j++) {
                    var c:uint=bn.getPixel(i,j);
                    if(c<=t){
                    //     cn.setPixel(i, j, color);
                        var a:Number=Math.random()*(Math.PI*2)
                        
                        var p:P=new P(Math.cos(a)*(r)+r, Math.sin(a)*(r)+r)
                        p.tx=i;
                        p.ty=j;
                        p.trgx=p.tx;
                        p.trgy=p.ty;
                        ps.push(p)
                        
                    }
                } 
            }
        }
    }
}
class P{
    public var x:Number,y:Number;
    public var vx:Number,vy:Number;
    public var ax:Number,ay:Number;
    public var tx:Number,ty:Number;
    public var flag:Boolean=false;
    public var fx:Number,fy:Number;
    public var trgx:Number,trgy:Number;
    public function P(x:Number,y:Number)
    {
    this.x=x;
    this.y=y;
    fx=x;
    fy=y;
    }

}