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

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

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


FORKED
  1. // forked from soundkitchen's 風が吹くようななにか
  2. /**
  3.  *  Graphics 使って高速化してみたよ。
  4.  */
  5. package
  6. {
  7.     import flash.display.Bitmap;
  8.     import flash.display.BitmapData;
  9.     import flash.display.BlendMode;
  10.     import flash.display.Graphics;
  11.     import flash.display.Shape;
  12.     import flash.display.Sprite;
  13.     import flash.events.Event;
  14.     import flash.events.MouseEvent;
  15.     import flash.geom.Point;
  16.     import flash.geom.Rectangle;
  17.     import net.hires.debug.Stats;
  18.     [SWF(frameRate=60, width=465, height=465, backgroundColor=0x000000)]
  19.     public class Main extends Sprite
  20.     {
  21.         private var _canvas:Shape;
  22.         private var _film:BitmapData;
  23.         private var _rect:Rectangle;
  24.         private var _particles:Vector.<Particle>;
  25.         private var _mouseDowned:Boolean;
  26.         public function Main()
  27.         {
  28.             addEventListener(Event.ADDED_TO_STAGE, initialize);
  29.         }
  30.         private function initialize(evt:Event):void
  31.         {
  32.             removeEventListener(evt.type, arguments.callee);
  33.             _particles = new Vector.<Particle>();
  34.             _canvas = new Shape();
  35.             _rect = new Rectangle(00, stage.stageWidth, stage.stageHeight);
  36.             _film = new BitmapData(stage.stageWidth, stage.stageHeight, true0);
  37.             addChild(new Bitmap(_film));
  38.             addChildAt(new Stats(), 0);
  39.             addEventListener(Event.ENTER_FRAME, step);
  40.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  41.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  42.         }
  43.         private function step(evt:Event):void
  44.         {
  45.             var i:int,
  46.                 l:int,
  47.                 p:Particle,
  48.                 m:Point,
  49.                 g:Graphics;
  50.             if (_mouseDowned)
  51.             {
  52.                 for (i=0; i<5; i++)
  53.                 {
  54.                     addParticle();
  55.                 }
  56.             }
  57.             g = _canvas.graphics;
  58.             g.clear();
  59.             l = _particles.length;
  60.             for (i=0; i<l; i++)
  61.             {
  62.                 p = _particles[i];
  63.                 p.update();
  64.                 g.beginFill(0xDFFE9E, p.alpha);
  65.                 for each (m in p.points)
  66.                 {
  67.                     if (m == p.points[0])
  68.                     {
  69.                         g.moveTo(p.x + m.x, p.y + m.y);
  70.                     }
  71.                     else
  72.                     {
  73.                         g.lineTo(p.x + m.x, p.y + m.y);
  74.                     }
  75.                 }
  76.                 g.endFill();
  77.                 if (p.alpha <= 0 || !_rect.contains(p.x, p.y))
  78.                 {
  79.                     _particles.splice(i--, 1);
  80.                     l--;
  81.                 }
  82.             }
  83.             _film.lock();
  84.             _film.fillRect(_film.rect, 0);
  85.             _film.draw(_canvas, nullnull);
  86.             _film.unlock();
  87.         }
  88.         private function addParticle():void
  89.         {
  90.             _particles.push(new Particle(mouseX, mouseY));
  91.         }
  92.         private function mouseDownHandler(evt:MouseEvent):void
  93.         {
  94.             _mouseDowned = true;
  95.         }
  96.         private function mouseUpHandler(evt:MouseEvent):void
  97.         {
  98.             _mouseDowned = false;
  99.         }
  100.     }
  101. }
  102. import flash.geom.Point;
  103. class Particle
  104. {
  105.     //  TODO: remove such a poor code.
  106.     public static const FRAME_RATE:int = 60;
  107.     public static const WIND:Number = 9;
  108.     public static const GRAVITY:Number = -3;
  109.     //  declared each rect positions.
  110.     private static var P1:Point = new Point(-5, -2);
  111.     private static var P2:Point = new Point(5, -2);
  112.     private static var P3:Point = new Point(52);
  113.     private static var P4:Point = new Point(-52);
  114.     private static var DEFAULT_POINTS:Array = [P1, P2, P3, P4];
  115.     public var points:Vector.<Point>;
  116.     public var x:Number;
  117.     public var y:Number;
  118.     public var alpha:Number;
  119.     private var _vx:Number;
  120.     private var _vy:Number;
  121.     private var _tick:uint;
  122.     public function Particle(x:Number, y:Number)
  123.     {
  124.         this.x = x;
  125.         this.y = y;
  126.         this.alpha = 1;
  127.         this.points = new Vector.<Point>(4true);
  128.         var strength:Number,
  129.             angle:Number,
  130.             i:int,
  131.             a:Number,
  132.             p:Point;
  133.         angle = Math.random() * Math.PI * 2;
  134.         for (i=0; i<DEFAULT_POINTS.length; i++)
  135.         {
  136.             p = DEFAULT_POINTS[i];
  137.             strength = Math.sqrt(p.x * p.x + p.y * p.y);
  138.             a = Math.atan2(p.y, p.x);
  139.             a += angle;
  140.             points[i] = Point.polar(strength, a);
  141.         }
  142.         strength = Math.random() * 4;
  143.         _vx = strength * Math.cos(angle);
  144.         _vy = strength * Math.sin(angle);
  145.         _tick = 0;
  146.     }
  147.     public function update():void
  148.     {
  149.         var t:Number,
  150.             p:Point,
  151.             strength:Number,
  152.             angle:Number;
  153.         _tick++;
  154.         t = _tick / FRAME_RATE;
  155.         x += WIND * t + _vx;
  156.         y += GRAVITY * t + _vy;
  157.         alpha -= .02;
  158.         for each (p in points)
  159.         {
  160.             strength = Math.sqrt(p.x * p.x + p.y * p.y);
  161.             angle = Math.atan2(p.y, p.x);
  162.             angle += Math.PI * 2 / FRAME_RATE;
  163.             p.x = strength * Math.cos(angle);
  164.             p.y = strength * Math.sin(angle);
  165.         }
  166.     }
  167. }
noswf
Get Adobe Flash Player