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

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

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


FORKED
  1. // forked from HaraMakoto's Light Effect
  2. // forked from cellfusion's Particle Sample
  3. // Particle Sample Part2 http://wonderfl.net/code/22a06782b22470146ea62c1040ba435928fbf21c
  4. // 浮かんで消える http://wonderfl.net/code/c4b218d595f245b5ac1eb97903e10e5fe973dbac
  5. // write as3 code here..
  6. // 光の表現のサンプルです。
  7. package
  8. {
  9.     import flash.display.Bitmap;
  10.     import flash.display.BitmapData;
  11.     import flash.display.Sprite;
  12.     import flash.display.StageQuality;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.filters.BlurFilter;
  16.     import flash.geom.Matrix;
  17.     import flash.geom.Point;
  18.     //import net.hires.debug.Stats;
  19.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]  
  20.     
  21.     public class LightEffect extends Sprite
  22.     {
  23.         private var _mirrorBmp:Bitmap = new Bitmap();
  24.         private var _mirrorBmd:BitmapData = new BitmapData(465,465,false,0);
  25.         private var _mirrorMtx:Matrix;
  26.         private var _transPoint:Point = new Point(465/2465/2);
  27.         
  28.         private var _particleLayer:Sprite = new Sprite();
  29.         
  30.         private var _particles:Array = [];
  31.         private var _emitter:Emitter;
  32.         // 1フレーム間に発生させる Particle 数
  33.         private const PARTICLE_NUM:uint = 1;
  34.         public function LightEffect()
  35.         {
  36.             stage.quality = StageQuality.LOW;
  37.             setup();
  38.             //addChild(new Stats());
  39.         }
  40.         
  41.         private function setup():void
  42.         {
  43.                _mirrorBmp.bitmapData = _mirrorBmd;
  44.                addChild(_mirrorBmp);
  45.            
  46.             _emitter = new Emitter();
  47.             addChild(_particleLayer);
  48.             _particleLayer.addChild(_emitter);
  49.             for (var i:uint = 0; i < 100; i++) {
  50.                 _particles.push(new Particle());
  51.             }
  52.             addEventListener(Event.ENTER_FRAME, draw);
  53.             
  54.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
  55.         }
  56.         
  57.         private function draw(event:Event):void
  58.         {
  59.             _emitter.update();
  60.             for each (var p:Particle in _particles) {
  61.                 if (!p.destroy) {
  62.                     if (p.y >= 10) {
  63.                            p.vy *= -0.9;
  64.                         p.vx *= -0.9
  65.                     } 
  66.                     p.update();
  67.                 }
  68.             }
  69.             
  70.             //拡大反射
  71.             _mirrorMtx = new Matrix();
  72.             var ram:Number = 30+2*Math.random();
  73.             _mirrorMtx.translate(-_transPoint.x, -_transPoint.y);
  74.             _mirrorMtx.scale(ram,ram); 
  75.             _mirrorMtx.translate(_transPoint.x, _transPoint.y);
  76.             _mirrorBmd.fillRect(_mirrorBmd.rect, 0x00000000);
  77.             _mirrorBmd.draw( _particleLayer, _mirrorMtx);
  78.             
  79.         }
  80.         
  81.         private function mouseDown(event:MouseEvent):void
  82.         {
  83.             addEventListener(Event.ENTER_FRAME, createParticle);
  84.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
  85.             _transPoint.x = mouseX;
  86.             _transPoint.y = mouseY;
  87.         }
  88.         private function mouseUp(event:MouseEvent):void
  89.         {
  90.             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
  91.             removeEventListener(Event.ENTER_FRAME, createParticle);
  92.         }
  93.         
  94.         private function createParticle(event:Event):void
  95.         {
  96.             var count:uint = 0;
  97.             for each (var p:Particle in _particles) {
  98.                 // 停止している Particle を探す
  99.                 if (p.destroy) {
  100.                     p.x = _emitter.x;
  101.                     p.y = _emitter.y;
  102.                     p.init();
  103.                     _particleLayer.addChild(p);
  104.                     count++;
  105.                 }
  106.                 if (count > PARTICLE_NUM) break;
  107.             }
  108.         }
  109.     }
  110. }
  111. import flash.display.Sprite;
  112. import flash.display.GradientType;
  113. class Emitter extends Sprite
  114. {
  115.     public var vx:Number = 0;
  116.     public var vy:Number = 0;
  117.     public function Emitter(){}
  118.     public function update():void
  119.     {
  120.         var dx:Number = root.mouseX - x;
  121.         var dy:Number = root.mouseY - y;
  122.         var d:Number = Math.sqrt(dx*dx+dy*dy) * 0.2;
  123.         var rad:Number = Math.atan2(dy, dx);
  124.         vx += Math.cos(rad)*d;
  125.         vy += Math.sin(rad)*d;
  126.         vx *= 0.7;
  127.         vy *= 0.7;
  128.         x += vx;
  129.         y += vy;
  130.     }
  131. }
  132. import flash.filters.BlurFilter;
  133. import flash.geom.Matrix;
  134. import flash.display.SpreadMethod;
  135. class Particle extends Sprite
  136. {
  137.     public var vx:Number;
  138.     public var vy:Number;
  139.     public var life:Number;
  140.     public var size:Number;
  141.     private var _count:uint;
  142.     private var _destroy:Boolean;
  143.     
  144.     /**
  145.      * ブラウン運動関連
  146.      */
  147.     private var friction:Number = 0.99;
  148.     private var vectx:Number = -0.4;
  149.     private var vecty:Number = -0.8;
  150.     private var xrandom:Number = 0.8;
  151.     private var yrandom:Number = 0.3;
  152.     public function Particle()
  153.     {
  154.         size = Math.random() * 30;
  155.         
  156.         var red:uint = Math.floor(Math.random()*100+156);
  157.         var blue:uint = Math.floor(Math.random()*100+100);
  158.         var green:uint = Math.floor(Math.random()*156);
  159.         var color:Number = (red << 16) | (green << 8) | (blue);
  160.         
  161.         var fillType:String = GradientType.RADIAL;
  162.         var colors:Array = [color , 0x000000];
  163.         var alphas:Array = [100100];
  164.         var ratios:Array = [0x00, 0xFF];
  165.         var mat:Matrix = new Matrix();
  166.         mat.createGradientBox(size * 2, size * 20, -size, -size);
  167.         var spreadMethod:String = SpreadMethod.PAD;
  168.         graphics.clear();
  169.         graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spreadMethod);
  170.         graphics.drawCircle(00, size);
  171.         graphics.endFill();
  172.         
  173.         // 大量のオブジェクトを重ねるとおかしくなる
  174.         blendMode = "add";
  175.         _destroy = true;
  176.     }
  177.     public function init():void
  178.     {
  179.         vx = Math.random() * 20 - 10;
  180.         vy = Math.random() * 20 - 10;
  181.         life = Math.random() * 20 + 10;
  182.         _count = 0;
  183.         _destroy = false;
  184.     }
  185.     
  186.     public function update():void
  187.     {
  188.         vx += Math.random()*xrandom + vectx;
  189.         vy += Math.random()*yrandom + vecty;
  190.         vx *= friction;
  191.         vy *= friction;
  192.         
  193.         x += vx;
  194.         y += vy;
  195.         _count++;
  196.         
  197.         // 死亡フラグ
  198.         if (life < _count) {
  199.             _destroy = true;
  200.             parent.removeChild(this);
  201.         }
  202.     }
  203.     public function get destroy():Boolean
  204.     {
  205.         return _destroy;
  206.     }
  207. }
noswf
  1. // forked from HaraMakoto's Light Effect
  2. // forked from cellfusion's Particle Sample
  3. // Particle Sample Part2 http://wonderfl.net/code/22a06782b22470146ea62c1040ba435928fbf21c
  4. // 浮かんで消える http://wonderfl.net/code/c4b218d595f245b5ac1eb97903e10e5fe973dbac
  5. // write as3 code here..
  6. // 光の表現のサンプルです。
  7. package
  8. {
  9.     import flash.display.Bitmap;
  10.     import flash.display.BitmapData;
  11.     import flash.display.Sprite;
  12.     import flash.display.StageQuality;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.filters.BlurFilter;
  16.     import flash.geom.Matrix;
  17.     import flash.geom.Point;
  18.     //import net.hires.debug.Stats;
  19.     [SWF(width="465", height="465", backgroundColor="0xff0000", frameRate="30")]  
  20.     
  21.     public class LightEffect extends Sprite
  22.     {
  23.         private var _mirrorBmp:Bitmap = new Bitmap();
  24.         private var _mirrorBmd:BitmapData = new BitmapData(465,465,false,0);
  25.         private var _mirrorMtx:Matrix;
  26.         private var _transPoint:Point = new Point(465/2465/2);
  27.         
  28.         private var _particleLayer:Sprite = new Sprite();
  29.         
  30.         private var _particles:Array = [];
  31.         private var _emitter:Emitter;
  32.         // 1フレーム間に発生させる Particle 数
  33.         private const PARTICLE_NUM:uint = 1;
  34.         public function LightEffect()
  35.         {
  36.             stage.quality = StageQuality.LOW;
  37.             setup();
  38.             //addChild(new Stats());
  39.         }
  40.         
  41.         private function setup():void
  42.         {
  43.                _mirrorBmp.bitmapData = _mirrorBmd;
  44.                addChild(_mirrorBmp);
  45.            
  46.             _emitter = new Emitter();
  47.             addChild(_particleLayer);
  48.             _particleLayer.addChild(_emitter);
  49.             for (var i:uint = 0; i < 100; i++) {
  50.                 _particles.push(new Particle());
  51.             }
  52.             addEventListener(Event.ENTER_FRAME, draw);
  53.             
  54.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
  55.         }
  56.         
  57.         private function draw(event:Event):void
  58.         {
  59.             _emitter.update();
  60.             for each (var p:Particle in _particles) {
  61.                 if (!p.destroy) {
  62.                     if (p.y >= 10) {
  63.                            p.vy *= -0.9;
  64.                         p.vx *= -0.9
  65.                     } 
  66.                     p.update();
  67.                 }
  68.             }
  69.             
  70.             //拡大反射
  71.             _mirrorMtx = new Matrix();
  72.             var ram:Number = 30+2*Math.random();
  73.             _mirrorMtx.translate(-_transPoint.x, -_transPoint.y);
  74.             _mirrorMtx.scale(ram,ram); 
  75.             _mirrorMtx.translate(_transPoint.x, _transPoint.y);
  76.             _mirrorBmd.fillRect(_mirrorBmd.rect, 0x00000000);
  77.             _mirrorBmd.draw( _particleLayer, _mirrorMtx);
  78.             
  79.         }
  80.         
  81.         private function mouseDown(event:MouseEvent):void
  82.         {
  83.             addEventListener(Event.ENTER_FRAME, createParticle);
  84.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
  85.             _transPoint.x = mouseX;
  86.             _transPoint.y = mouseY;
  87.         }
  88.         private function mouseUp(event:MouseEvent):void
  89.         {
  90.             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
  91.             removeEventListener(Event.ENTER_FRAME, createParticle);
  92.         }
  93.         
  94.         private function createParticle(event:Event):void
  95.         {
  96.             var count:uint = 0;
  97.             for each (var p:Particle in _particles) {
  98.                 // 停止している Particle を探す
  99.                 if (p.destroy) {
  100.                     p.x = _emitter.x;
  101.                     p.y = _emitter.y;
  102.                     p.init();
  103.                     _particleLayer.addChild(p);
  104.                     count++;
  105.                 }
  106.                 if (count > PARTICLE_NUM) break;
  107.             }
  108.         }
  109.     }
  110. }
  111. import flash.display.Sprite;
  112. import flash.display.GradientType;
  113. class Emitter extends Sprite
  114. {
  115.     public var vx:Number = 0;
  116.     public var vy:Number = 0;
  117.     public function Emitter(){}
  118.     public function update():void
  119.     {
  120.         var dx:Number = root.mouseX - x;
  121.         var dy:Number = root.mouseY - y;
  122.         var d:Number = Math.sqrt(dx*dx+dy*dy) * 0.2;
  123.         var rad:Number = Math.atan2(dy, dx);
  124.         vx += Math.cos(rad)*d;
  125.         vy += Math.sin(rad)*d;
  126.         vx *= 0.7;
  127.         vy *= 0.7;
  128.         x += vx;
  129.         y += vy;
  130.     }
  131. }
  132. import flash.filters.BlurFilter;
  133. import flash.geom.Matrix;
  134. import flash.display.SpreadMethod;
  135. class Particle extends Sprite
  136. {
  137.     public var vx:Number;
  138.     public var vy:Number;
  139.     public var life:Number;
  140.     public var size:Number;
  141.     private var _count:uint;
  142.     private var _destroy:Boolean;
  143.     
  144.     /**
  145.      * ブラウン運動関連
  146.      */
  147.     private var friction:Number = 0.99;
  148.     private var vectx:Number = -0.4;
  149.     private var vecty:Number = -0.8;
  150.     private var xrandom:Number = 0.8;
  151.     private var yrandom:Number = 0.3;
  152.     public function Particle()
  153.     {
  154.         size = Math.random() * 30;
  155.         
  156.         var red:uint = Math.floor(Math.random()*100+156);
  157.         var blue:uint = Math.floor(Math.random()*100+100);
  158.         var green:uint = Math.floor(Math.random()*156);
  159.         var color:Number = (red << 16) | (green << 8) | (blue);
  160.         
  161.         var fillType:String = GradientType.RADIAL;
  162.         var colors:Array = [color , 0x000000];
  163.         var alphas:Array = [100100];
  164.         var ratios:Array = [0x00, 0xFF];
  165.         var mat:Matrix = new Matrix();
  166.         mat.createGradientBox(size * 2, size * 20, -size, -size);
  167.         var spreadMethod:String = SpreadMethod.PAD;
  168.         graphics.clear();
  169.         graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spreadMethod);
  170.         graphics.drawCircle(00, size);
  171.         graphics.endFill();
  172.         
  173.         // 大量のオブジェクトを重ねるとおかしくなる
  174.         blendMode = "add";
  175.         _destroy = true;
  176.     }
  177.     public function init():void
  178.     {
  179.         vx = Math.random() * 20 - 10;
  180.         vy = Math.random() * 20 - 10;
  181.         life = Math.random() * 20 + 10;
  182.         _count = 0;
  183.         _destroy = false;
  184.     }
  185.     
  186.     public function update():void
  187.     {
  188.         vx += Math.random()*xrandom + vectx;
  189.         vy += Math.random()*yrandom + vecty;
  190.         vx *= friction;
  191.         vy *= friction;
  192.         
  193.         x += vx;
  194.         y += vy;
  195.         _count++;
  196.         
  197.         // 死亡フラグ
  198.         if (life < _count) {
  199.             _destroy = true;
  200.             parent.removeChild(this);
  201.         }
  202.     }
  203.     public function get destroy():Boolean
  204.     {
  205.         return _destroy;
  206.     }
  207. }
noswf
  1. // forked from HaraMakoto's Light Effect
  2. // forked from cellfusion's Particle Sample
  3. // Particle Sample Part2 http://wonderfl.net/code/22a06782b22470146ea62c1040ba435928fbf21c
  4. // 浮かんで消える http://wonderfl.net/code/c4b218d595f245b5ac1eb97903e10e5fe973dbac
  5. // write as3 code here..
  6. // 光の表現のサンプルです。
  7. package
  8. {
  9.     import flash.display.Bitmap;
  10.     import flash.display.BitmapData;
  11.     import flash.display.Sprite;
  12.     import flash.display.StageQuality;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.filters.BlurFilter;
  16.     import flash.geom.Matrix;
  17.     import flash.geom.Point;
  18.     //import net.hires.debug.Stats;
  19.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]  
  20.     
  21.     public class LightEffect extends Sprite
  22.     {
  23.         private var _mirrorBmp:Bitmap = new Bitmap();
  24.         private var _mirrorBmd:BitmapData = new BitmapData(465,465,false,0);
  25.         private var _mirrorMtx:Matrix;
  26.         private var _transPoint:Point = new Point(465/2465/2);
  27.         
  28.         private var _particleLayer:Sprite = new Sprite();
  29.         
  30.         private var _particles:Array = [];
  31.         private var _emitter:Emitter;
  32.         // 1フレーム間に発生させる Particle 数
  33.         private const PARTICLE_NUM:uint = 1;
  34.         public function LightEffect()
  35.         {
  36.             stage.quality = StageQuality.LOW;
  37.             setup();
  38.             //addChild(new Stats());
  39.         }
  40.         
  41.         private function setup():void
  42.         {
  43.                _mirrorBmp.bitmapData = _mirrorBmd;
  44.                addChild(_mirrorBmp);
  45.            
  46.             _emitter = new Emitter();
  47.             addChild(_particleLayer);
  48.             _particleLayer.addChild(_emitter);
  49.             for (var i:uint = 0; i < 100; i++) {
  50.                 _particles.push(new Particle());
  51.             }
  52.             addEventListener(Event.ENTER_FRAME, draw);
  53.             
  54.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
  55.         }
  56.         
  57.         private function draw(event:Event):void
  58.         {
  59.             _emitter.update();
  60.             for each (var p:Particle in _particles) {
  61.                 if (!p.destroy) {
  62.                     if (p.y >= 10) {
  63.                            p.vy *= -0.9;
  64.                         p.vx *= -0.9
  65.                     } 
  66.                     p.update();
  67.                 }
  68.             }
  69.             
  70.             //拡大反射
  71.             _mirrorMtx = new Matrix();
  72.             var ram:Number = 30+2*Math.random();
  73.             _mirrorMtx.translate(-_transPoint.x, -_transPoint.y);
  74.             _mirrorMtx.scale(ram,ram); 
  75.             _mirrorMtx.translate(_transPoint.x, _transPoint.y);
  76.             _mirrorBmd.fillRect(_mirrorBmd.rect, 0x00000000);
  77.             _mirrorBmd.draw( _particleLayer, _mirrorMtx);
  78.             
  79.         }
  80.         
  81.         private function mouseDown(event:MouseEvent):void
  82.         {
  83.             addEventListener(Event.ENTER_FRAME, createParticle);
  84.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
  85.             _transPoint.x = mouseX;
  86.             _transPoint.y = mouseY;
  87.         }
  88.         private function mouseUp(event:MouseEvent):void
  89.         {
  90.             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
  91.             removeEventListener(Event.ENTER_FRAME, createParticle);
  92.         }
  93.         
  94.         private function createParticle(event:Event):void
  95.         {
  96.             var count:uint = 0;
  97.             for each (var p:Particle in _particles) {
  98.                 // 停止している Particle を探す
  99.                 if (p.destroy) {
  100.                     p.x = _emitter.x;
  101.                     p.y = _emitter.y;
  102.                     p.init();
  103.                     _particleLayer.addChild(p);
  104.                     count++;
  105.                 }
  106.                 if (count > PARTICLE_NUM) break;
  107.             }
  108.         }
  109.     }
  110. }
  111. import flash.display.Sprite;
  112. import flash.display.GradientType;
  113. class Emitter extends Sprite
  114. {
  115.     public var vx:Number = 0;
  116.     public var vy:Number = 0;
  117.     public function Emitter(){}
  118.     public function update():void
  119.     {
  120.         var dx:Number = root.mouseX - x;
  121.         var dy:Number = root.mouseY - y;
  122.         var d:Number = Math.sqrt(dx*dx+dy*dy) * 0.2;
  123.         var rad:Number = Math.atan2(dy, dx);
  124.         vx += Math.cos(rad)*d;
  125.         vy += Math.sin(rad)*d;
  126.         vx *= 0.7;
  127.         vy *= 0.7;
  128.         x += vx;
  129.         y += vy;
  130.     }
  131. }
  132. import flash.filters.BlurFilter;
  133. import flash.geom.Matrix;
  134. import flash.display.SpreadMethod;
  135. class Particle extends Sprite
  136. {
  137.     public var vx:Number;
  138.     public var vy:Number;
  139.     public var life:Number;
  140.     public var size:Number;
  141.     private var _count:uint;
  142.     private var _destroy:Boolean;
  143.     
  144.     /**
  145.      * ブラウン運動関連
  146.      */
  147.     private var friction:Number = 0.99;
  148.     private var vectx:Number = -0.4;
  149.     private var vecty:Number = -0.8;
  150.     private var xrandom:Number = 0.8;
  151.     private var yrandom:Number = 0.3;
  152.     public function Particle()
  153.     {
  154.         size = Math.random() * 30;
  155.         
  156.         var red:uint = Math.floor(Math.random()*100+156);
  157.         var blue:uint = Math.floor(Math.random()*100+100);
  158.         var green:uint = Math.floor(Math.random()*156);
  159.         var color:Number = (red << 16) | (green << 8) | (blue);
  160.         
  161.         var fillType:String = GradientType.RADIAL;
  162.         var colors:Array = [color , 0x000000];
  163.         var alphas:Array = [100100];
  164.         var ratios:Array = [0x00, 0xFF];
  165.         var mat:Matrix = new Matrix();
  166.         mat.createGradientBox(size * 2, size * 20, -size, -size);
  167.         var spreadMethod:String = SpreadMethod.PAD;
  168.         graphics.clear();
  169.         graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spreadMethod);
  170.         graphics.drawCircle(00, size);
  171.         graphics.endFill();
  172.         
  173.         // 大量のオブジェクトを重ねるとおかしくなる
  174.         blendMode = "add";
  175.         _destroy = true;
  176.     }
  177.     public function init():void
  178.     {
  179.         vx = Math.random() * 20 - 10;
  180.         vy = Math.random() * 20 - 10;
  181.         life = Math.random() * 20 + 10;
  182.         _count = 0;
  183.         _destroy = false;
  184.     }
  185.     
  186.     public function update():void
  187.     {
  188.         vx += Math.random()*xrandom + vectx;
  189.         vy += Math.random()*yrandom + vecty;
  190.         vx *= friction;
  191.         vy *= friction;
  192.         
  193.         x += vx;
  194.         y += vy;
  195.         _count++;
  196.         
  197.         // 死亡フラグ
  198.         if (life < _count) {
  199.             _destroy = true;
  200.             parent.removeChild(this);
  201.         }
  202.     }
  203.     public function get destroy():Boolean
  204.     {
  205.         return _destroy;
  206.     }
  207. }
noswf
  1. // forked from HaraMakoto's Light Effect
  2. // forked from cellfusion's Particle Sample
  3. // Particle Sample Part2 http://wonderfl.net/code/22a06782b22470146ea62c1040ba435928fbf21c
  4. // 浮かんで消える http://wonderfl.net/code/c4b218d595f245b5ac1eb97903e10e5fe973dbac
  5. // write as3 code here..
  6. // 光の表現のサンプルです。
  7. package
  8. {
  9.     import flash.display.Bitmap;
  10.     import flash.display.BitmapData;
  11.     import flash.display.Sprite;
  12.     import flash.display.StageQuality;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.filters.BlurFilter;
  16.     import flash.geom.Matrix;
  17.     import flash.geom.Point;
  18.     //import net.hires.debug.Stats;
  19.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]  
  20.     
  21.     public class LightEffect extends Sprite
  22.     {
  23.         private var _mirrorBmp:Bitmap = new Bitmap();
  24.         private var _mirrorBmd:BitmapData = new BitmapData(465,465,false,0);
  25.         private var _mirrorMtx:Matrix;
  26.         private var _transPoint:Point = new Point(465/2465/2);
  27.         
  28.         private var _particleLayer:Sprite = new Sprite();
  29.         
  30.         private var _particles:Array = [];
  31.         private var _emitter:Emitter;
  32.         // 1フレーム間に発生させる Particle 数
  33.         private const PARTICLE_NUM:uint = 1;
  34.         public function LightEffect()
  35.         {
  36.             stage.quality = StageQuality.LOW;
  37.             setup();
  38.             //addChild(new Stats());
  39.         }
  40.         
  41.         private function setup():void
  42.         {
  43.                _mirrorBmp.bitmapData = _mirrorBmd;
  44.                addChild(_mirrorBmp);
  45.            
  46.             _emitter = new Emitter();
  47.             addChild(_particleLayer);
  48.             _particleLayer.addChild(_emitter);
  49.             for (var i:uint = 0; i < 100; i++) {
  50.                 _particles.push(new Particle());
  51.             }
  52.             addEventListener(Event.ENTER_FRAME, draw);
  53.             
  54.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
  55.         }
  56.         
  57.         private function draw(event:Event):void
  58.         {
  59.             _emitter.update();
  60.             for each (var p:Particle in _particles) {
  61.                 if (!p.destroy) {
  62.                     if (p.y >= 10) {
  63.                            p.vy *= -0.9;
  64.                         p.vx *= -0.9
  65.                     } 
  66.                     p.update();
  67.                 }
  68.             }
  69.             
  70.             //拡大反射
  71.             _mirrorMtx = new Matrix();
  72.             var ram:Number = 30+2*Math.random();
  73.             _mirrorMtx.translate(-_transPoint.x, -_transPoint.y);
  74.             _mirrorMtx.scale(ram,ram); 
  75.             _mirrorMtx.translate(_transPoint.x, _transPoint.y);
  76.             _mirrorBmd.fillRect(_mirrorBmd.rect, 0x00000000);
  77.             _mirrorBmd.draw( _particleLayer, _mirrorMtx);
  78.             
  79.         }
  80.         
  81.         private function mouseDown(event:MouseEvent):void
  82.         {
  83.             addEventListener(Event.ENTER_FRAME, createParticle);
  84.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
  85.             _transPoint.x = mouseX;
  86.             _transPoint.y = mouseY;
  87.         }
  88.         private function mouseUp(event:MouseEvent):void
  89.         {
  90.             stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
  91.             removeEventListener(Event.ENTER_FRAME, createParticle);
  92.         }
  93.         
  94.         private function createParticle(event:Event):void
  95.         {
  96.             var count:uint = 0;
  97.             for each (var p:Particle in _particles) {
  98.                 // 停止している Particle を探す
  99.                 if (p.destroy) {
  100.                     p.x = _emitter.x;
  101.                     p.y = _emitter.y;
  102.                     p.init();
  103.                     _particleLayer.addChild(p);
  104.                     count++;
  105.                 }
  106.                 if (count > PARTICLE_NUM) break;
  107.             }
  108.         }
  109.     }
  110. }
  111. import flash.display.Sprite;
  112. import flash.display.GradientType;
  113. class Emitter extends Sprite
  114. {
  115.     public var vx:Number = 0;
  116.     public var vy:Number = 0;
  117.     public function Emitter(){}
  118.     public function update():void
  119.     {
  120.         var dx:Number = root.mouseX - x;
  121.         var dy:Number = root.mouseY - y;
  122.         var d:Number = Math.sqrt(dx*dx+dy*dy) * 0.2;
  123.         var rad:Number = Math.atan2(dy, dx);
  124.         vx += Math.cos(rad)*d;
  125.         vy += Math.sin(rad)*d;
  126.         vx *= 0.7;
  127.         vy *= 0.7;
  128.         x += vx;
  129.         y += vy;
  130.     }
  131. }
  132. import flash.filters.BlurFilter;
  133. import flash.geom.Matrix;
  134. import flash.display.SpreadMethod;
  135. class Particle extends Sprite
  136. {
  137.     public var vx:Number;
  138.     public var vy:Number;
  139.     public var life:Number;
  140.     public var size:Number;
  141.     private var _count:uint;
  142.     private var _destroy:Boolean;
  143.     
  144.     /**
  145.      * ブラウン運動関連
  146.      */
  147.     private var friction:Number = 0.99;
  148.     private var vectx:Number = -0.4;
  149.     private var vecty:Number = -0.8;
  150.     private var xrandom:Number = 0.8;
  151.     private var yrandom:Number = 0.3;
  152.     public function Particle()
  153.     {
  154.         size = Math.random() * 30;
  155.         
  156.         var red:uint = Math.floor(Math.random()*100+156);
  157.         var blue:uint = Math.floor(Math.random()*100+100);
  158.         var green:uint = Math.floor(Math.random()*156);
  159.         var color:Number = (red << 16) | (green << 8) | (blue);
  160.         
  161.         var fillType:String = GradientType.RADIAL;
  162.         var colors:Array = [color , 0x000000];
  163.         var alphas:Array = [100100];
  164.         var ratios:Array = [0x00, 0xFF];
  165.         var mat:Matrix = new Matrix();
  166.         mat.createGradientBox(size * 2, size * 20, -size, -size);
  167.         var spreadMethod:String = SpreadMethod.PAD;
  168.         graphics.clear();
  169.         graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spreadMethod);
  170.         graphics.drawCircle(00, size);
  171.         graphics.endFill();
  172.         
  173.         // 大量のオブジェクトを重ねるとおかしくなる
  174.         blendMode = "add";
  175.         _destroy = true;
  176.     }
  177.     public function init():void
  178.     {
  179.         vx = Math.random() * 20 - 10;
  180.         vy = Math.random() * 20 - 10;
  181.         life = Math.random() * 20 + 10;
  182.         _count = 0;
  183.         _destroy = false;
  184.     }
  185.     
  186.     public function update():void
  187.     {
  188.         vx += Math.random()*xrandom + vectx;
  189.         vy += Math.random()*yrandom + vecty;
  190.         vx *= friction;
  191.         vy *= friction;
  192.         
  193.         x += vx;
  194.         y += vy;
  195.         _count++;
  196.         
  197.         // 死亡フラグ
  198.         if (life < _count) {
  199.             _destroy = true;
  200.             parent.removeChild(this);
  201.         }
  202.     }
  203.     public function get destroy():Boolean
  204.     {
  205.         return _destroy;
  206.     }
  207. }
noswf
  1. // forked from HaraMakoto's Light Effect
  2. // forked from cellfusion's Particle Sample
  3. // Particle Sample Part2 http://wonderfl.net/code/22a06782b22470146ea62c1040ba435928fbf21c
  4. // 浮かんで消える http://wonderfl.net/code/c4b218d595f245b5ac1eb97903e10e5fe973dbac
  5. // write as3 code here..
  6. // 光の表現のサンプルです。
  7. //0番ピンにつなげた光センサで明るさを検知。
  8. //暗いと光って明るいと消えます。
  9. package
  10. {
  11.     import flash.display.Bitmap;
  12.     import flash.display.BitmapData;
  13.     import flash.display.Sprite;
  14.     import flash.display.StageQuality;
  15.     import flash.events.Event;
  16.     import flash.events.MouseEvent;
  17.     import flash.filters.BlurFilter;
  18.     import flash.geom.Matrix;
  19.     import flash.geom.Point;
  20.     //import net.hires.debug.Stats;
  21.     
  22.     import funnel.*;
  23.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]  
  24.     
  25.     public class LightEffect extends Sprite
  26.     {
  27.         private var _mirrorBmp:Bitmap = new Bitmap();
  28.         private var _mirrorBmd:BitmapData = new BitmapData(465,465,false,0);
  29.         private var _mirrorMtx:Matrix;
  30.         private var _transPoint:Point = new Point(465/2465/2);
  31.         
  32.         private var _particleLayer:Sprite = new Sprite();
  33.         
  34.         private var _particles:Array = [];
  35.         private var _emitter:Emitter;
  36.         // 1フレーム間に発生させる Particle 数
  37.         private const PARTICLE_NUM:uint = 1;
  38.         
  39.         private var gainer:Gainer;
  40.         private var sensor:Pin;
  41.         public function LightEffect()
  42.         {
  43.                 gainer = new Gainer();
  44.                 sensor = gainer.analogInput(0);
  45.                 sensor.addFilter(new SetPoint([0.60.05]));
  46.                 sensor.addEventListener(PinEvent.FALLING_EDGE, sensorDown);
  47.                 
  48.             stage.quality = StageQuality.LOW;
  49.             setup();
  50.             //addChild(new Stats());
  51.         }
  52.         
  53.         private function setup():void
  54.         {
  55.                _mirrorBmp.bitmapData = _mirrorBmd;
  56.                addChild(_mirrorBmp);
  57.            
  58.             _emitter = new Emitter();
  59.             addChild(_particleLayer);
  60.             _particleLayer.addChild(_emitter);
  61.             for (var i:uint = 0; i < 100; i++) {
  62.                 _particles.push(new Particle());
  63.             }
  64.             addEventListener(Event.ENTER_FRAME, draw);
  65.         }
  66.         
  67.         private function draw(event:Event):void
  68.         {
  69.             _emitter.update();
  70.             for each (var p:Particle in _particles) {
  71.                 if (!p.destroy) {
  72.                     if (p.y >= 10) {
  73.                            p.vy *= -0.9;
  74.                         p.vx *= -0.9
  75.                     } 
  76.                     p.update();
  77.                 }
  78.             }
  79.             
  80.             //拡大反射
  81.             _mirrorMtx = new Matrix();
  82.             var ram:Number = 30+2*Math.random();
  83.             _mirrorMtx.translate(-_transPoint.x, -_transPoint.y);
  84.             _mirrorMtx.scale(ram,ram); 
  85.             _mirrorMtx.translate(_transPoint.x, _transPoint.y);
  86.             _mirrorBmd.fillRect(_mirrorBmd.rect, 0x00000000);
  87.             _mirrorBmd.draw( _particleLayer, _mirrorMtx);
  88.             
  89.         }
  90.         
  91.         private function sensorDown(event:PinEvent):void
  92.         {
  93.             addEventListener(Event.ENTER_FRAME, createParticle);
  94.             sensor.addEventListener(PinEvent.RISING_EDGE, sensorUp);
  95.             _transPoint.x = stage.stageWidth/2;
  96.             _transPoint.y = stage.stageHeight/2;
  97.         }
  98.         private function sensorUp(event:PinEvent):void
  99.         {
  100.                 sensor.removeEventListener(PinEvent.RISING_EDGE, sensorUp);
  101.             removeEventListener(Event.ENTER_FRAME, createParticle);
  102.         }
  103.         
  104.         private function createParticle(event:Event):void
  105.         {
  106.             var count:uint = 0;
  107.             for each (var p:Particle in _particles) {
  108.                 // 停止している Particle を探す
  109.                 if (p.destroy) {
  110.                     p.x = _emitter.x;
  111.                     p.y = _emitter.y;
  112.                     p.init();
  113.                     _particleLayer.addChild(p);
  114.                     count++;
  115.                 }
  116.                 if (count > PARTICLE_NUM) break;
  117.             }
  118.         }
  119.     }
  120. }
  121. import flash.display.Sprite;
  122. import flash.display.GradientType;
  123. class Emitter extends Sprite
  124. {
  125.     public var vx:Number = 0;
  126.     public var vy:Number = 0;
  127.     public function Emitter(){}
  128.     public function update():void
  129.     {
  130.         var dx:Number = stage.stageWidth/2 + 7 - x;
  131.         var dy:Number = stage.stageHeight/2 - 7 - y;
  132.         var d:Number = Math.sqrt(dx*dx+dy*dy) * 0.2;
  133.         var rad:Number = Math.atan2(dy, dx);
  134.         vx += Math.cos(rad)*d;
  135.         vy += Math.sin(rad)*d;
  136.         vx *= 0.7;
  137.         vy *= 0.7;
  138.         x += vx;
  139.         y += vy;
  140.     }
  141. }
  142. import flash.filters.BlurFilter;
  143. import flash.geom.Matrix;
  144. import flash.display.SpreadMethod;
  145. class Particle extends Sprite
  146. {
  147.     public var vx:Number;
  148.     public var vy:Number;
  149.     public var life:Number;
  150.     public var size:Number;
  151.     private var _count:uint;
  152.     private var _destroy:Boolean;
  153.     
  154.     /**
  155.      * ブラウン運動関連
  156.      */
  157.     private var friction:Number = 0.99;
  158.     private var vectx:Number = -0.4;
  159.     private var vecty:Number = -0.8;
  160.     private var xrandom:Number = 0.8;
  161.     private var yrandom:Number = 0.3;
  162.     public function Particle()
  163.     {
  164.         size = Math.random() * 30;
  165.         
  166.         var red:uint = Math.floor(Math.random()*100+156);
  167.         var blue:uint = Math.floor(Math.random()*100+100);
  168.         var green:uint = Math.floor(Math.random()*156);
  169.         var color:Number = (red << 16) | (green << 8) | (blue);
  170.         
  171.         var fillType:String = GradientType.RADIAL;
  172.         var colors:Array = [color , 0x000000];
  173.         var alphas:Array = [100100];
  174.         var ratios:Array = [0x00, 0xFF];
  175.         var mat:Matrix = new Matrix();
  176.         mat.createGradientBox(size * 2, size * 20, -size, -size);
  177.         var spreadMethod:String = SpreadMethod.PAD;
  178.         graphics.clear();
  179.         graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spreadMethod);
  180.         graphics.drawCircle(00, size);
  181.         graphics.endFill();
  182.         
  183.         // 大量のオブジェクトを重ねるとおかしくなる
  184.         blendMode = "add";
  185.         _destroy = true;
  186.     }
  187.     public function init():void
  188.     {
  189.         vx = Math.random() * 20 - 10;
  190.         vy = Math.random() * 20 - 10;
  191.         life = Math.random() * 20 + 10;
  192.         _count = 0;
  193.         _destroy = false;
  194.     }
  195.     
  196.     public function update():void
  197.     {
  198.         vx += Math.random()*xrandom + vectx;
  199.         vy += Math.random()*yrandom + vecty;
  200.         vx *= friction;
  201.         vy *= friction;
  202.         
  203.         x += vx;
  204.         y += vy;
  205.         _count++;
  206.         
  207.         // 死亡フラグ
  208.         if (life < _count) {
  209.             _destroy = true;
  210.             parent.removeChild(this);
  211.         }
  212.     }
  213.     public function get destroy():Boolean
  214.     {
  215.         return _destroy;
  216.     }
  217. }
noswf
Get Adobe Flash Player