※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : soundkitchen's forked from: 2009-2-26 爆発エフェクト [diff(21)]

FORKED

forked from: forked from: 2009-2-26 爆発エフェクト Blurをとってみた(爆発エフェクト) [diff(5)]

  1. // forked from soundkitchen's forked from: forked from: 2009-2-26 爆発エフェクト
  2. // forked from soundkitchen's forked from: 2009-2-26 爆発エフェクト
  3. // forked from hikipuro's 2009-2-26 爆発エフェクト
  4. package
  5. {
  6.     import flash.display.Sprite;
  7.     import flash.display.Bitmap;
  8.     import flash.display.BitmapData;
  9.     import flash.events.Event;
  10.     import flash.events.MouseEvent;
  11.     import flash.filters.BitmapFilterQuality;
  12.     import flash.filters.BlurFilter;
  13.     import flash.geom.Point;
  14.     [SWF(width="500", height="500", backgroundColor="0x000000", frameRate="60")]
  15.     public class Main extends Sprite
  16.     {
  17.         private var particles:Array;
  18.         private var output:BitmapData;
  19.         private var blur:BlurFilter;
  20.         private var mouseDownFlag:Boolean;
  21.         public function Main()
  22.         {
  23.             addEventListener(Event.ADDED_TO_STAGE, initialize);
  24.         }
  25.         private function initialize(e:Event=null):void
  26.         {
  27.             removeEventListener(e.type, arguments.callee);
  28.             mouseDownFlag = false;
  29.             particles = new Array();
  30. //          blur = new BlurFilter(2, 2, BitmapFilterQuality.MEDIUM);
  31.             output = new BitmapData(stage.stageWidth, stage.stageHeight, false0);
  32.             addChild(new Bitmap(output));
  33.             stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
  34.             stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
  35.             stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  36.         }
  37.         private function onMouseDown(event:Event):void
  38.         {
  39.             mouseDownFlag = true;
  40.         }
  41.         private function onMouseUp(event:Event):void
  42.         {
  43.             mouseDownFlag = false;
  44.         }
  45.         private function onEnterFrame(event:Event):void
  46.         {
  47.             if (mouseDownFlag)
  48.             {
  49.                 addParticle(mouseX, mouseY);
  50.             }
  51.             render();
  52.         }
  53.         public function addParticle(x: Number, y: Number):void
  54.         {
  55.             for (var i:int = 0; i < 30; i++)
  56.             {
  57.                 var len: Number,
  58.                     angle: Number;
  59.                 len = Math.random() * 10;
  60.                 angle = Math.random() * Math.PI * 2;
  61.                 particles.push(new Particle(x, y, len, angle));
  62.             }
  63.         }
  64.         public function render():void
  65.         {
  66.             var deleteArray:Array = new Array();
  67.             output.lock();
  68.             for each (var particle:Particle in particles)
  69.             {
  70.                 particle.draw(output);
  71.                 if (!particle.isAlive) {
  72.                     var i:int = particles.indexOf(particle);
  73.                     particles.splice(i, 1);
  74.                 }
  75.             }
  76. //            output.applyFilter(output, output.rect, new Point(), blur);
  77.             output.unlock();
  78.         }
  79.     }
  80. }
  81. import flash.display.BitmapData;
  82. import flash.geom.Point;
  83. class Particle
  84. {
  85.     private var _x:Number;
  86.     private var _y:Number;
  87.     private var _vx:Number;
  88.     private var _vy:Number;
  89.     private var _energy:uint;
  90.     private var _life:int;
  91.     /**
  92.      *  コンストラクタ
  93.      */
  94.     public function Particle(x:Number, y:Number, len:Number=0, angle:Number=0)
  95.     {
  96.         //  極座標を直行点座標に変換。
  97.         var p:Point = Point.polar(len, angle);
  98.         _x = x;
  99.         _y = y;
  100.         _vx = p.x;
  101.         _vy = p.y;
  102.         _energy = genColor();
  103.         _life = 120;
  104.     }
  105.     /**
  106.      *  実際に書き込む。
  107.      */
  108.     public function draw(buffer:BitmapData):void
  109.     {
  110.         buffer.setPixel(_x, _y, _energy);
  111.         _x += _vx;
  112.         _y += _vy;
  113.         //  必要な値を減衰
  114.         _vx *= .98;
  115.         _vy *= .98;
  116.         _energy *= .98;
  117.         _life--;
  118.     }
  119.     /**
  120.      *  生存チェック
  121.      */
  122.     public function get isAlive():Boolean
  123.     {
  124.         return _life > 0;
  125.     }
  126. }
  127. /**
  128.  *  適当に色を作る。
  129.  */
  130. function genColor():uint
  131. {
  132.     var f:Function = function():int
  133.     {
  134.         return Math.floor(Math.random() * 256);
  135.     }
  136.     return f() << 16|f() << 8|f();
  137. }
noswf
Get Adobe Flash Player