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

[練習]Bitmap?

/**
 * Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mQ7L
 */

package {
    import flash.display.BlendMode;
    import flash.filters.GlowFilter;
    import flash.filters.BlurFilter;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.PixelSnapping;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
//   
    import flash.system.Security;  
    
    import caurina.transitions.Tweener;
    
    [SWF(backgroundColor=0x0)]
   
    public class FlashTest extends Sprite {
        
        private var file:String="http://assets.wonderfl.net/images/related_images/3/37/37f5/37f5f9a17dfa799dadba38e45e568d4da9b4ee23";
        private var w:int = 20;
        private var h:int = 20;
        
        private var bmArr:Array = [];
        private var mxArr:Array = [];
        private var myArr:Array = [];
        
        private var isHiyoko:Boolean = true;
        private var isMouse:Boolean = false;
        
        
        private var sp:Sprite;
        private var angle:int = 0;
        
  
        public function FlashTest() {
            init();
        }//FrashTest
        
        private function init():void{
            //
            Security.allowDomain("assets.wonderfl.net");
            Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
            // 
            
            var my_load:Loader=new Loader();
            var my_url:URLRequest=new URLRequest(file);
            my_load.load(my_url);
            my_load.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
        }
            
//ロードが終了後のイベント            
            private function onComplete(event:Event):void{
                

                
                var content:Bitmap = event.target.content;
            var my_bmd:BitmapData=new BitmapData(content.width, content.height);
            my_bmd.draw(content);
            var my_bm:Bitmap = new Bitmap(my_bmd);
           for(var x:int = 0; x < my_bm.width; x++){
               for(var y:int = 0; y < my_bm.height; y++){
                    
                 var color:uint = my_bmd.getPixel(x, y);
                  if(color < 0x333333){
                       my_bmd.setPixel(x, y, 0x000000);
                  }
               }

            }

            
            
            for(var i:int = 0; i < w; i++){
                for(var k:int = 0; k < h; k++){
                    var bd:BitmapData = new BitmapData(my_bm.width / w, my_bm.height / h);
                    var mat:Matrix = new Matrix();
                    mat.translate(-i * bd.width, -k * bd.height);
                    bd.draw(my_bm, mat);
                    var bm:Bitmap = new Bitmap(bd);
                     
                    
 
                     
                     
                    bm.filters = [new GlowFilter(0xffffff, 1, 5, 5), new BlurFilter(2, 2, 1)];
                    bm.blendMode = BlendMode.ADD;
                    
                    addChild(bm);
                    bmArr.push(bm);
                    
                   // bm.x = Math.random() * 465;
                   // bm.y = Math.random() * 465;
                    bm.alpha = 1;
                    
                    bm.x = - my_bm.width / 2 + 232 + i * bm.width;
                    bm.y = - my_bm.height / 2 + 232 + k * bm.height;
                    
                    var mx:Number = - my_bm.width / 2 + 232 + i * bm.width;
                    var my:Number = - my_bm.height / 2 + 232 + k * bm.height;
                    mxArr.push(mx);
                    myArr.push(my);
                    
          //          if(i == w -1 && k == h -1){
         //           Tweener.addTween(bm, {x:mx, y:my, alpha:1, delay:(k + i ) / 5, time:2, onComplete:mouseMove});
           //         }else{
           //          Tweener.addTween(bm, {x:mx, y:my, alpha:1, delay:(k + i ) / 5, time:2});
           //         }
            //        function mouseMove():void{
            //            isMouse = true
                    
             //       }
                   

                    
                }

            }
         //   stage.addEventListener(MouseEvent.CLICK, onClick);
            //addEventListener(Event.ENTER_FRAME, mouseEnter);
            
           
           
           
           
           /* 
            var bd:BitmapData = new BitmapData(100, 100);
            var mat:Matrix = new Matrix();
            mat.translate(0, -50);
 
            bd.draw(my_bm, mat);
            var bmd:Bitmap = new Bitmap(bd);
            
            var bd2:BitmapData = new BitmapData(100, 100);
            var mat2:Matrix = new Matrix();
            mat2.translate(-100, -50);
            
            bd2.draw(my_bm, mat2);
            var bmd2:Bitmap = new Bitmap(bd2);

  
            addChild(bmd);
            addChild(bmd2);
            bmd.rotation = Math.random() * 1000;  
            bmd.x = Math.random() * 465;
            bmd.y = Math.random() * 465;
            bmd2.x = Math.random() * 465;
            bmd2.y = Math.random() * 465;
            
            Tweener.addTween(bmd,{x:0, y:0, delay:3, rotation:0, time:5});
            Tweener.addTween(bmd2,{x:101, y:0, delay:3, time:5});
        */    

            }//onComplete
            
        

            private function mouseEnter(e:Event):void{
              //  if(isMouse == true){
                for(var i:int = 0; i < bmArr.length; i++){
                var bm:Bitmap = bmArr[i];
                var radius:Number = Math.atan2(bm.y - mouseY, bm.x - mouseX);
                var dist:Number = Math.sqrt(Math.pow(mouseX - bm.x, 2) + Math.pow(mouseY - bm.y, 2));
                var per:Number = 150 / dist;
                bm.x += per * Math.cos(radius) + (mxArr[i] - bm.x) * 0.05;
                bm.y += per * Math.sin(radius) + (myArr[i] - bm.y) * 0.05;
                
                }
                }
            //}

            
   /*         
            private function onClick(e:MouseEvent):void{
                if(isHiyoko){
                    for(var i:int = 0; i < bmArr.length; i++){
                    if(i < 100){
                    var radian:Number = 360 / 100 * i * Math.PI / 180;
                    var xx:Number = 232 + Math.cos(radian) * 300;
                    var yy:Number = 232 + Math.sin(radian) * 300;
                    Tweener.addTween(bmArr[i], {x:xx, y:yy, delay:(Math.random() * i / 5) /100, alpha:1, time:2});
                    }else if(i < 190){
                    var radian1:Number = 360 / 90 * i * Math.PI / 180;
                    var xx1:Number = 232 + Math.cos(radian1) * 250;
                    var yy1:Number = 232 + Math.sin(radian1) * 250;
                    Tweener.addTween(bmArr[i], {x:xx1, y:yy1, delay:(Math.random() * i / 5) /100, alpha:0.8, time:2});    
                    }else if(i < 270){
                        var radian2:Number = 360 / 80 * i * Math.PI / 180;
                    var xx2:Number = 232 + Math.cos(radian2) * 200;
                    var yy2:Number = 232 + Math.sin(radian2) * 200;
                    Tweener.addTween(bmArr[i], {x:xx2, y:yy2, delay:(Math.random() * i / 5) /100, alpha:0.6, time:2});
                    }else if(i < 340){
                        var radian3:Number = 360 / 70 * i * Math.PI / 180;
                    var xx3:Number = 232 + Math.cos(radian3) * 150;
                    var yy3:Number = 232 + Math.sin(radian3) * 150;
                    Tweener.addTween(bmArr[i], {x:xx3, y:yy3, delay:(Math.random() * i / 5) /100, alpha:0.4, time:2});
                    }else if(i < 400){
                        var radian4:Number = 360 / 60 * i * Math.PI / 180;
                    var xx4:Number = 232 + Math.cos(radian4) * 100;
                    var yy4:Number = 232 + Math.sin(radian4) * 100;
                    Tweener.addTween(bmArr[i], {x:xx4, y:yy4, delay:(Math.random() * i / 5) /100, alpha:0.2, time:2});
                    }else if(i < 450){
                        var radian5:Number = 360 / 50 * i * Math.PI / 180;
                    var xx5:Number = 232 + Math.cos(radian5) * 50;
                    var yy5:Number = 232 + Math.sin(radian5) * 50;
                    Tweener.addTween(bmArr[i], {x:xx5, y:yy5, delay:(Math.random() * i / 5) /100, alpha:0.1, time:2});
                    }

                    }
                   
            //    removeEventListener(Event.ENTER_FRAME, onSyu);
            //    addEventListener(Event.ENTER_FRAME, onKaku);
                isHiyoko = false;
                }else{
             //       removeEventListener(Event.ENTER_FRAME, onKaku);
              //      addEventListener(Event.ENTER_FRAME, onSyu);
              for(var k:int = 0; k < bmArr.length; k++){
                    Tweener.addTween(bmArr[k], {x:mxArr[k], y:myArr[k], alpha:1, delay:Math.random() * (bmArr.length -k) / 200, time:2});
              }
                    isHiyoko = true;
                }
                
            }
            private function onKaku(e:Event):void{
                for(var i:int = 0; i < bmArr.length; i++){
                    var radian:Number = 360 / bmArr.length * i * Math.PI / 180;
                    var vx:Number = ((232 + Math.cos(radian) * 300) - bmArr[i].x) * 0.1;
                    var vy:Number = ((232 + Math.sin(radian) * 300) - bmArr[i].y) * 0.1;
                    bmArr[i].x += vx;
                    bmArr[i].y += vy;
                }

            }
            private function onSyu(e:Event):void{
                for(var i:int = 0; i < bmArr.length; i++){
                var vx:Number = (mxArr[i] - bmArr[i].x) * 0.1;
                var vy:Number = (myArr[i] - bmArr[i].y) * 0.1;
                bmArr[i].x += vx;
                bmArr[i].y += vy;
                }
            }
*/


    

    }//class
}//package