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

はじけ飛ぶ何か

LIVE CODING 2010/07/16
黒いもやもや
クリックまたはキーを押すとではじけ飛ぶ
Get Adobe Flash player
by shohei909 16 Jul 2010
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/g4Yr
 */

//LIVE CODING 2010/07/16
//黒いもやもや
//クリックまたはキーを押すとではじけ飛ぶ



package {
    import flash.events.*;
    import flash.display.Sprite;
    import com.bit101.components.FPSMeter;
    
    
    public class FlashTest extends Sprite {
        public var map:SmokeMap = new SmokeMap(465,465);
        public function FlashTest() {
            // write as3 code here..
            addChild(map);
            new FPSMeter(this);
            onDown();
            map.create(22, 100, 15 ,28);
            map.create(22, 250, 15 ,28);
            map.create(22, 400, 15 ,28);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
           stage.addEventListener(KeyboardEvent.KEY_DOWN,onDown);
        }
        public function onDown(e:Event = null):void{
            map.del()==false
        }
    }
}




import flash.geom.Rectangle;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;


class SmokeMap extends Bitmap{
    public var color:uint = 0xFF000000;
    private var cores:Vector.<Object> = new Vector.<Object>();
    private var points:Vector.<Object> = new Vector.<Object>();
    private var transMap:BitmapData;
    private var rate:Number = 60;
    private var filter:BlurFilter = new BlurFilter(5,5,1);
    private var aliveRect:Rectangle;
    
    
    
    public function SmokeMap(w:int,h:int){
        aliveRect = new Rectangle(-100,-100,w+200,h+200);
        transMap = new BitmapData(w,h,true,0xFF333333);
        super(new BitmapData(w,h,true));
        this.addEventListener( "enterFrame", onFrame );
    }
    
    public function create(x:int,y:int,n:int,w:int=10,r:int = 10):void{
        for(var i:int=0;i<n;i++){
            var core:Object = { x:x+i*w,y:y };
            cores.push( core );
            for(var j:int=0;j<5;j++){
                var randX:Number = (Math.random()*2-1);
                var randY:Number = (Math.random()*2-1);
                points.push( {   
                                 x: core.x+randX*r,
                                 y: core.y+randY*r,
                                 dy: randX*r,
                                 dx: randY*r,
                                 target: core,
                                 chase: true,
                                 life: 40
                              } );
            }
        }
    }
    
    
    
    
    private function onFrame(e:Event):void{
        move();
        drow();
    }
    
    
    private function drow():void{
        var b:BitmapData = bitmapData;
        b.lock();
        
        b.merge(transMap,b.rect,new Point(),100,100,100,256);
        
        var l:int = points.length;
        for(var i:int=l-1;i>-1;i--){
            var p:Object = points[i];
            b.fillRect(new Rectangle(p.x,p.y,15,15),color*p.life/10);
        }
        
        b.applyFilter(b,b.rect,new Point(),filter);
        
        
        b.unlock();
    }
    
    
    private function move():void{
        var l:int = points.length;
        for(var i:int=0;i<l;i++){
            var p:Object = points[i];
            p.x += p.dx;
            p.y += p.dy;
            if(p.chase){
                var core:Object = p.target;
                var rx:Number = core.x-p.x;
                var ry:Number = core.y-p.y;
                var deg:Number = Math.atan2( rx , ry );
                var r:Number = (rx*rx+ry*ry)/100;
                p.dx += Math.sin(deg)*r;
                p.dy += Math.cos(deg)*r;
            }else{
                p.life--;
                if(p.life<0 || bitmapData.rect.contains(p.x,p.y)==false){
                    points.splice(i,1);
                    l--;i--;
                }
            }
        }
    }
    
    public function del(n:int = 0):Boolean{
        var l:int = points.length;
        if(n < cores.length){
            var c:Object = cores[n];
            cores.splice(n,1);
            for(var i:int=0;i<l;i++){
                var p:Object = points[i];
                if(p.target == c){
                    p.chase = false;
                    p.dx *= 5;
                    p.dy *= 5;
                }
            }
            return true;
        }
        return false;
    }
}