※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!
wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)
forked from: forked from: 2009-2-26 爆発エフェクト Blurをとってみた(爆発エフェクト)
- // forked from soundkitchen's forked from: forked from: 2009-2-26 爆発エフェクト
- // forked from soundkitchen's forked from: 2009-2-26 爆発エフェクト
- // forked from hikipuro's 2009-2-26 爆発エフェクト
- package
- {
- import flash.display.Sprite;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.filters.BitmapFilterQuality;
- import flash.filters.BlurFilter;
- import flash.geom.Point;
- [SWF(width="500", height="500", backgroundColor="0x000000", frameRate="60")]
- public class Main extends Sprite
- {
- private var particles:Array;
- private var output:BitmapData;
- private var blur:BlurFilter;
- private var mouseDownFlag:Boolean;
- public function Main()
- {
- addEventListener(Event.ADDED_TO_STAGE, initialize);
- }
- private function initialize(e:Event=null):void
- {
- removeEventListener(e.type, arguments.callee);
- mouseDownFlag = false;
- particles = new Array();
- // blur = new BlurFilter(2, 2, BitmapFilterQuality.MEDIUM);
- output = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
- addChild(new Bitmap(output));
- stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
- stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
- stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
- }
- private function onMouseDown(event:Event):void
- {
- mouseDownFlag = true;
- }
- private function onMouseUp(event:Event):void
- {
- mouseDownFlag = false;
- }
- private function onEnterFrame(event:Event):void
- {
- if (mouseDownFlag)
- {
- addParticle(mouseX, mouseY);
- }
- render();
- }
- public function addParticle(x: Number, y: Number):void
- {
- for (var i:int = 0; i < 30; i++)
- {
- var len: Number,
- angle: Number;
- len = Math.random() * 10;
- angle = Math.random() * Math.PI * 2;
- particles.push(new Particle(x, y, len, angle));
- }
- }
- public function render():void
- {
- var deleteArray:Array = new Array();
- output.lock();
- for each (var particle:Particle in particles)
- {
- particle.draw(output);
- if (!particle.isAlive) {
- var i:int = particles.indexOf(particle);
- particles.splice(i, 1);
- }
- }
- // output.applyFilter(output, output.rect, new Point(), blur);
- output.unlock();
- }
- }
- }
- import flash.display.BitmapData;
- import flash.geom.Point;
- class Particle
- {
- private var _x:Number;
- private var _y:Number;
- private var _vx:Number;
- private var _vy:Number;
- private var _energy:uint;
- private var _life:int;
- /**
- * コンストラクタ
- */
- public function Particle(x:Number, y:Number, len:Number=0, angle:Number=0)
- {
- // 極座標を直行点座標に変換。
- var p:Point = Point.polar(len, angle);
- _x = x;
- _y = y;
- _vx = p.x;
- _vy = p.y;
- _energy = genColor();
- _life = 120;
- }
- /**
- * 実際に書き込む。
- */
- public function draw(buffer:BitmapData):void
- {
- buffer.setPixel(_x, _y, _energy);
- _x += _vx;
- _y += _vy;
- // 必要な値を減衰
- _vx *= .98;
- _vy *= .98;
- _energy *= .98;
- _life--;
- }
- /**
- * 生存チェック
- */
- public function get isAlive():Boolean
- {
- return _life > 0;
- }
- }
- /**
- * 適当に色を作る。
- */
- function genColor():uint
- {
- var f:Function = function():int
- {
- return Math.floor(Math.random() * 256);
- }
- return f() << 16|f() << 8|f();
- }
notice: 


