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

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

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


forked from : yanbaka's HANABI [diff(130)]

FORKED
  1. // forked from osamX's forked from: HANABI
  2. // forked from yanbaka's HANABI
  3. // コード全然違うけど参考にさせてもらいました。
  4. // なんだこれ?
  5. package 
  6. {
  7.     import flash.display.Bitmap;
  8.     import flash.display.BitmapData;
  9.     import flash.display.BlendMode;
  10.     import flash.display.Sprite;
  11.     import flash.events.Event;
  12.     import flash.events.TimerEvent;
  13.     import flash.filters.BlurFilter;
  14.     import flash.geom.ColorTransform;
  15.     import flash.geom.Matrix;
  16.     import flash.geom.Point;
  17.     import flash.geom.Rectangle;
  18.     import flash.utils.Timer;
  19.     
  20.     [SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "30")]
  21.      public class Main extends Sprite 
  22.     {
  23.         private const WIDTH:Number = 465;
  24.         private const HEIGHT:Number = 465;
  25.         private const MAX:Number = Math.sqrt(WIDTH * WIDTH + HEIGHT * HEIGHT);
  26.         private const NUM:uint = 400;
  27.         
  28.         private var particles:Array;
  29.         private var bmd:BitmapData;
  30.         private var cTra:ColorTransform;
  31.         private var rect:Rectangle;
  32.         private var timer:Timer;
  33.         private var groupNum:uint = 0;
  34.         
  35.         public function Main():void {
  36.             init();
  37.         }
  38.         
  39.         private function init():void {
  40.             bmd = new BitmapData(WIDTH, HEIGHT, false, 0x0);
  41.             addChild(new Bitmap(bmd)) as Bitmap;
  42.             
  43.             rect = new Rectangle(00, WIDTH, HEIGHT);
  44.             cTra = new ColorTransform(.8, .8, .91.0);
  45.             
  46.             //パーティクルを作る
  47.             particles = [];
  48.             for (var i:uint = 0; i < NUM; i++) {
  49.                 var p:Particle = new Particle(WIDTH * Math.random(), HEIGHT * Math.random(), 00, i % 3);
  50.                 particles.push(p);
  51.             }
  52.             
  53.             stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  54.             
  55.             timer = new Timer(1000);
  56.             timer.addEventListener(TimerEvent.TIMER, resetFunc);
  57.             timer.start();
  58.         }
  59.         
  60.         private function resetFunc(event:TimerEvent):void {
  61.             groupNum = (groupNum + 1) % 3;
  62.         }
  63.         
  64.         private function onEnterFrame(event:Event):void {
  65.             bmd.lock();
  66.             bmd.applyFilter(bmd, rect, new Point(), new BlurFilter(11));
  67.             bmd.colorTransform(rect, cTra);
  68.             
  69.             for (var i:uint = 0; i < NUM; i++ ) {
  70.                 var p:Particle = particles[i];
  71.                 
  72.                 //一番近い子探すよ
  73.                 var nearp:Particle;
  74.                 var min:Number = MAX;
  75.                 var pnum:uint;
  76.                 for (var j:uint = 0; j < NUM; j++ ) {
  77.                     if (i == j) continue;
  78.                     nearp = particles[j];
  79.                     if (p.getLength(nearp) < min) pnum = j; //近いっぽい
  80.                 }
  81.                 nearp = particles[pnum];//見つけた
  82.                 
  83.                 //ベクトル決定
  84.                 if (p.group == groupNum) {
  85.                     p.vx = (nearp.x - p.x) / 10;
  86.                     p.vy = (nearp.y - p.y) / 10;
  87.                 }else{
  88.                     p.vx = 300 / (nearp.x - p.x);
  89.                     p.vy = 300 / (nearp.y - p.y);
  90.                 }
  91.                 
  92.                 //位置決定
  93.                 p.x = p.x + p.vx;
  94.                 p.y = p.y + p.vy;
  95.                 
  96.                 if (p.x < 0 ) p.x = WIDTH- p.x % -WIDTH;
  97.                 else if (p.x >= WIDTH) p.x %= WIDTH;
  98.                 
  99.                 if (p.y < 0 ) p.y = HEIGHT- p.y % -HEIGHT;
  100.                 else if (p.y >= HEIGHT) p.y %= HEIGHT;
  101.                 
  102.                 bmd.setPixel32(p.x, p.y, 0xFFFFFFFF);
  103.             }
  104.             bmd.unlock();
  105.         }
  106.     }
  107. }
  108. class Particle 
  109. {
  110.     public var x:Number;
  111.     public var y:Number;
  112.     public var vx:Number;
  113.     public var vy:Number;
  114.     public var group:uint;
  115.     
  116.     public function Particle( _x:Number = 0, _y:Number = 0, _vx:Number = 0, _vy:Number = 0, _group:uint = 0) {
  117.         this.x = _x;
  118.         this.y = _y;
  119.         this.vx = _vx;
  120.         this.vy = _vy;
  121.         this.group = _group;
  122.     }
  123.     
  124.     public function getLength(otherParticle:Particle):Number {
  125.         var length:Number;
  126.         length = (this.x - otherParticle.x) * (this.x - otherParticle.x);
  127.         length += (this.y - otherParticle.y) * (this.y - otherParticle.y);
  128.         return Math.sqrt(length);
  129.     }
  130.     
  131. }
noswf
Get Adobe Flash Player