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


embed

FORKED
  1. // forked from bkzen's 10万個ぱーてぃくる
  2. package  
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.     import net.hires.debug.Stats;
  10.     
  11.     /**
  12.      * なんかいっぱい動かすテスト
  13.      * 洗濯機みたいになってます。
  14.      * @author jc at bk-zen.com
  15.      */
  16.     [SWF(backgroundColor = "0x000000", frameRate = "1000")]
  17.     public class Test3 extends Sprite
  18.     {
  19.         protected const NUM_OF_PARTICLES: int = 100000;
  20.         private var main: TestMain;
  21.         
  22.         public function Test3() 
  23.         {
  24.             if (stage) init();
  25.             else addEventListener(Event.ADDED_TO_STAGE, init);
  26.         }
  27.         
  28.         private function init(e:Event = null):void 
  29.         {
  30.             removeEventListener(Event.ADDED_TO_STAGE, init);
  31.             //
  32.             main = new TestMain(stage.stageWidth, stage.stageHeight, NUM_OF_PARTICLES);
  33.             addChild(main.view);
  34.             addChild(new Stats());
  35.             stage.scaleMode = StageScaleMode.NO_SCALE;
  36.             stage.align = StageAlign.TOP_LEFT;
  37.             stage.addEventListener(Event.RESIZE, onResize);
  38.             stage.addEventListener(MouseEvent.CLICK, onClick);
  39.             addEventListener(Event.ENTER_FRAME, onEnter);
  40.             
  41.         }
  42.         
  43.         private function onClick(e:MouseEvent):void 
  44.         {
  45.             main.change();
  46.         }
  47.         
  48.         private function onEnter(e:Event):void 
  49.         {
  50.             main.draw(mouseX, mouseY);
  51.         }
  52.         // りサイズ (未実装)
  53.         private function onResize(e:Event):void 
  54.         {
  55.             main.resize(stage.stageWidth, stage.stageHeight);
  56.         }
  57.     }
  58. }
  59. import flash.display.Bitmap;
  60. import flash.display.BitmapData;
  61. import flash.geom.ColorTransform;
  62. import flash.geom.Point;
  63. import flash.utils.ByteArray;
  64. class TestMain
  65. {
  66.     private var w: int;
  67.     private var h: int;
  68.     private var mw: int;
  69.     private var mh: int;
  70.     public var view: Bitmap;
  71.     private var bmpData: BitmapData;
  72.     private var forceMap: BitmapData;
  73.     private var randomSeed: int;
  74.     private var particles: Array = [];
  75.     private var num: int;
  76.     private var color: uint = 0xF0F0FF;
  77.     private var count: int = 0;
  78.     private var colorTr: ColorTransform;
  79.     
  80.     public function TestMain(w: int, h: int, numOfParticles: int)
  81.     {
  82.         this.w = w;
  83.         mw = w >> 1;
  84.         this.h = h;
  85.         mh = h >> 1;
  86.         bmpData = new BitmapData(w, h, false, 0x00000000);
  87.         forceMap = new BitmapData(mw, mh, false);
  88.         forceMap.perlinNoise(mw >> 1, mh >> 14, Math.random() * 0xFFFF, falsetrue3);
  89.         view = new Bitmap(bmpData);
  90.         num = numOfParticles;
  91.         var i: int;
  92.         var p: Particle;
  93.         while (i < num)
  94.         {
  95.             p = new Particle();
  96.             p.x = Math.random() * w;
  97.             p.y = Math.random() * h;
  98.             particles.push(p);
  99.             i++;
  100.         }
  101.         colorTr = new ColorTransform(1111, -32, -16, -16);
  102.     }
  103.     // 描画、マウスの判定を後で追加予定
  104.     public function draw(mouseX: Number, mouseY: Number): void
  105.     {
  106.         var i: int;
  107.         var p: Particle;
  108.         var col: uint;
  109.         bmpData.lock();
  110.         bmpData.colorTransform(bmpData.rect, colorTr);
  111.         while (i < num)
  112.         {
  113.             p = Particle(particles[i]);
  114.             col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  115.             p.vx = p.vx * 0.1 + (( col >> 16 & 0xff)-128) * 0.004;
  116.             p.vy = p.vy * 0.1 + (( col >> 8 & 0xff)-128) * 0.004;
  117.             p.x += p.vx;
  118.             p.y += p.vy;
  119.             if (p.x < 0) p.x += w;
  120.             else if (p.x >= w) p.x -= w;
  121.             if (p.y < 0) p.y += h;
  122.             else if (p.y >= h) p.y -= h;
  123.             bmpData.setPixel(p.x, p.y, color);
  124.             i++;
  125.         }
  126.         bmpData.unlock();
  127.     }
  128.     
  129.     public function change(): void
  130.     {
  131.         forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xF000, falsetrue7);
  132.     }
  133.     
  134.     public function resize(w: Number, h: Number): void
  135.     {
  136.         this.w = w;
  137.         this.h = h;
  138.         if (bmpData) 
  139.         {
  140.             bmpData.dispose();
  141.         }
  142.         bmpData = new BitmapData(w, h, false, 0x00000000);
  143.         view.bitmapData = bmpData;
  144.     }
  145. }
  146. class Particle
  147. {
  148.     public var x: Number = 0;
  149.     public var y: Number = 0;
  150.     public var vx: Number = 0;
  151.     public var vy: Number = 0;
  152.     
  153.     public function Particle()
  154.     {
  155.         
  156.     }
  157. }
noswf
  1. // forked from bkzen's 10万個ぱーてぃくる
  2. package  
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.     import net.hires.debug.Stats;
  10.     
  11.     /**
  12.      * なんかいっぱい動かすテスト
  13.      * 洗濯機みたいになってます。
  14.      * @author jc at bk-zen.com
  15.      */
  16.     [SWF(backgroundColor = "0x000000", frameRate = "30")]
  17.     public class Test3 extends Sprite
  18.     {
  19.         protected const NUM_OF_PARTICLES: int = 100000;
  20.         private var main: TestMain;
  21.         
  22.         public function Test3() 
  23.         {
  24.             if (stage) init();
  25.             else addEventListener(Event.ADDED_TO_STAGE, init);
  26.         }
  27.         
  28.         private function init(e:Event = null):void 
  29.         {
  30.             removeEventListener(Event.ADDED_TO_STAGE, init);
  31.             //
  32.             main = new TestMain(stage.stageWidth, stage.stageHeight, NUM_OF_PARTICLES);
  33.             addChild(main.view);
  34.             addChild(new Stats());
  35.             stage.scaleMode = StageScaleMode.NO_SCALE;
  36.             stage.align = StageAlign.TOP_LEFT;
  37.             stage.addEventListener(Event.RESIZE, onResize);
  38.             stage.addEventListener(MouseEvent.CLICK, onClick);
  39.             addEventListener(Event.ENTER_FRAME, onEnter);
  40.             
  41.         }
  42.         
  43.         private function onClick(e:MouseEvent):void 
  44.         {
  45.             main.change();
  46.         }
  47.         
  48.         private function onEnter(e:Event):void 
  49.         {
  50.             main.draw(mouseX, mouseY);
  51.         }
  52.         // りサイズ (未実装)
  53.         private function onResize(e:Event):void 
  54.         {
  55.             main.resize(stage.stageWidth, stage.stageHeight);
  56.         }
  57.     }
  58. }
  59. import flash.display.Bitmap;
  60. import flash.display.BitmapData;
  61. import flash.geom.ColorTransform;
  62. import flash.geom.Point;
  63. import flash.utils.ByteArray;
  64. class TestMain
  65. {
  66.     private var w: int;
  67.     private var h: int;
  68.     private var mw: int;
  69.     private var mh: int;
  70.     public var view: Bitmap;
  71.     private var bmpData: BitmapData;
  72.     private var forceMap: BitmapData;
  73.     private var randomSeed: int;
  74.     private var particles: Array = [];
  75.     private var num: int;
  76.     private var color: uint = 0xF0F0FF;
  77.     private var count: int = 0;
  78.     private var colorTr: ColorTransform;
  79.     
  80.     public function TestMain(w: int, h: int, numOfParticles: int)
  81.     {
  82.         this.w = w;
  83.         mw = w >> 1;
  84.         this.h = h;
  85.         mh = h >> 1;
  86.         bmpData = new BitmapData(w, h, false, 0x00000000);
  87.         forceMap = new BitmapData(mw, mh, false);
  88.         forceMap.perlinNoise(mw >> 1, mh >> 14, Math.random() * 0xFFFF, falsetrue3);
  89.         view = new Bitmap(bmpData);
  90.         num = numOfParticles;
  91.         var i: int;
  92.         var p: Particle;
  93.         while (i < num)
  94.         {
  95.             p = new Particle();
  96.             p.x = Math.random() * w;
  97.             p.y = Math.random() * h;
  98.             particles.push(p);
  99.             i++;
  100.         }
  101.         colorTr = new ColorTransform(1111, -32, -16, -16);
  102.     }
  103.     // 描画、マウスの判定を後で追加予定
  104.     public function draw(mouseX: Number, mouseY: Number): void
  105.     {
  106.         var i: int;
  107.         var p: Particle;
  108.         var col: uint;
  109.         bmpData.lock();
  110.         bmpData.colorTransform(bmpData.rect, colorTr);
  111.         while (i < num)
  112.         {
  113.             p = Particle(particles[i]);
  114.             col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  115.             p.vx = p.vx * 0.98 + (( col >> 16 & 0xff)-128) * 0.004;
  116.             p.vy = p.vy * 0.98 + (( col >> 8 & 0xff)-128) * 0.004;
  117.             p.x += p.vx;
  118.             p.y += p.vy;
  119.             if (p.x < 0) p.x += w;
  120.             else if (p.x >= w) p.x -= w;
  121.             if (p.y < 0) p.y += h;
  122.             else if (p.y >= h) p.y -= h;
  123.             bmpData.setPixel(p.x, p.y, color);
  124.             i++;
  125.         }
  126.         bmpData.unlock();
  127.     }
  128.     
  129.     public function change(): void
  130.     {
  131.         forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xFFFF, falsetrue7);
  132.     }
  133.     
  134.     public function resize(w: Number, h: Number): void
  135.     {
  136.         this.w = w;
  137.         this.h = h;
  138.         if (bmpData) 
  139.         {
  140.             bmpData.dispose();
  141.         }
  142.         bmpData = new BitmapData(w, h, false, 0x00000000);
  143.         view.bitmapData = bmpData;
  144.     }
  145. }
  146. class Particle
  147. {
  148.     public var x: Number = 0;
  149.     public var y: Number = 0;
  150.     public var vx: Number = 0;
  151.     public var vy: Number = 0;
  152.     
  153.     public function Particle()
  154.     {
  155.         
  156.     }
  157. }
noswf
  1. // forked from bkzen's 10万個ぱーてぃくる
  2. package  
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.     import net.hires.debug.Stats;
  10.     
  11.     /**
  12.      * なんかいっぱい動かすテスト
  13.      * 洗濯機みたいになってます。
  14.      * @author jc at bk-zen.com
  15.      */
  16.     [SWF(backgroundColor = "0xFFFFFF", frameRate = "30")]
  17.     public class Test3 extends Sprite
  18.     {
  19.         protected const NUM_OF_PARTICLES: int = 100000;
  20.         private var main: TestMain;
  21.         
  22.         public function Test3() 
  23.         {
  24.             if (stage) init();
  25.             else addEventListener(Event.ADDED_TO_STAGE, init);
  26.         }
  27.         
  28.         private function init(e:Event = null):void 
  29.         {
  30.             removeEventListener(Event.ADDED_TO_STAGE, init);
  31.             //
  32.             main = new TestMain(stage.stageWidth, stage.stageHeight, NUM_OF_PARTICLES);
  33.             addChild(main.view);
  34.             addChild(new Stats());
  35.             stage.scaleMode = StageScaleMode.NO_SCALE;
  36.             stage.align = StageAlign.TOP_LEFT;
  37.             stage.addEventListener(Event.RESIZE, onResize);
  38.             stage.addEventListener(MouseEvent.CLICK, onClick);
  39.             addEventListener(Event.ENTER_FRAME, onEnter);
  40.             
  41.         }
  42.         
  43.         private function onClick(e:MouseEvent):void 
  44.         {
  45.             main.change();
  46.         }
  47.         
  48.         private function onEnter(e:Event):void 
  49.         {
  50.             main.draw(mouseX, mouseY);
  51.         }
  52.         // りサイズ (未実装)
  53.         private function onResize(e:Event):void 
  54.         {
  55.             main.resize(stage.stageWidth, stage.stageHeight);
  56.         }
  57.     }
  58. }
  59. import flash.display.Bitmap;
  60. import flash.display.BitmapData;
  61. import flash.geom.ColorTransform;
  62. import flash.geom.Point;
  63. import flash.utils.ByteArray;
  64. class TestMain
  65. {
  66.     private var w: int;
  67.     private var h: int;
  68.     private var mw: int;
  69.     private var mh: int;
  70.     public var view: Bitmap;
  71.     private var bmpData: BitmapData;
  72.     private var forceMap: BitmapData;
  73.     private var randomSeed: int;
  74.     private var particles: Array = [];
  75.     private var num: int;
  76.     private var color: uint = 0xF0F0FF;
  77.     private var count: int = 0;
  78.     private var colorTr: ColorTransform;
  79.     
  80.     public function TestMain(w: int, h: int, numOfParticles: int)
  81.     {
  82.         this.w = w;
  83.         mw = w >> 1;
  84.         this.h = h;
  85.         mh = h >> 1;
  86.         bmpData = new BitmapData(w, h, false, 0x00000000);
  87.         forceMap = new BitmapData(mw, mh, false);
  88.         forceMap.perlinNoise(mw >> 1, mh >> 14, Math.random() * 0xFFFF, falsetrue3);
  89.         view = new Bitmap(bmpData);
  90.         num = numOfParticles;
  91.         var i: int;
  92.         var p: Particle;
  93.         while (i < num)
  94.         {
  95.             p = new Particle();
  96.             p.x = Math.random() * w;
  97.             p.y = Math.random() * h;
  98.             particles.push(p);
  99.             i++;
  100.         }
  101.         colorTr = new ColorTransform(1111, -32, -16, -16);
  102.     }
  103.     // 描画、マウスの判定を後で追加予定
  104.     public function draw(mouseX: Number, mouseY: Number): void
  105.     {
  106.         var i: int;
  107.         var p: Particle;
  108.         var col: uint;
  109.         bmpData.lock();
  110.         bmpData.colorTransform(bmpData.rect, colorTr);
  111.         while (i < num)
  112.         {
  113.             p = Particle(particles[i]);
  114.             col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  115.             p.vx = p.vx * 0.98 + (( col >> 16 & 0xff)-128) * 0.004;
  116.             p.vy = p.vy * 0.98 + (( col >> 8 & 0xff)-128) * 0.004;
  117.             p.x += p.vx;
  118.             p.y += p.vy;
  119.             if (p.x < 0) p.x += w;
  120.             else if (p.x >= w) p.x -= w;
  121.             if (p.y < 0) p.y += h;
  122.             else if (p.y >= h) p.y -= h;
  123.             bmpData.setPixel(p.x, p.y, color);
  124.             i++;
  125.         }
  126.         bmpData.unlock();
  127.     }
  128.     
  129.     public function change(): void
  130.     {
  131.         forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xFFFF, falsetrue7);
  132.     }
  133.     
  134.     public function resize(w: Number, h: Number): void
  135.     {
  136.         this.w = w;
  137.         this.h = h;
  138.         if (bmpData) 
  139.         {
  140.             bmpData.dispose();
  141.         }
  142.         bmpData = new BitmapData(w, h, false, 0x00000000);
  143.         view.bitmapData = bmpData;
  144.     }
  145. }
  146. class Particle
  147. {
  148.     public var x: Number = 0;
  149.     public var y: Number = 0;
  150.     public var vx: Number = 0;
  151.     public var vy: Number = 0;
  152.     
  153.     public function Particle()
  154.     {
  155.         
  156.     }
  157. }
noswf
  1. // forked from bkzen's 10万個ぱーてぃくる
  2. package  
  3. {
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.     import net.hires.debug.Stats;
  10.     
  11.     /**
  12.      * なんかいっぱい動かすテスト
  13.      * 洗濯機みたいになってます。
  14.      * @author jc at bk-zen.com
  15.      */
  16.     [SWF(backgroundColor = "0x000000", frameRate = "30")]
  17.     public class Test3 extends Sprite
  18.     {
  19.         protected const NUM_OF_PARTICLES: int = 100000;
  20.         private var main: TestMain;
  21.         
  22.         public function Test3() 
  23.         {
  24.             if (stage) init();
  25.             else addEventListener(Event.ADDED_TO_STAGE, init);
  26.         }
  27.         
  28.         private function init(e:Event = null):void 
  29.         {
  30.             removeEventListener(Event.ADDED_TO_STAGE, init);
  31.             //
  32.             main = new TestMain(stage.stageWidth, stage.stageHeight, NUM_OF_PARTICLES);
  33.             addChild(main.view);
  34.             addChild(new Stats());
  35.             stage.scaleMode = StageScaleMode.NO_SCALE;
  36.             stage.align = StageAlign.TOP_LEFT;
  37.             stage.addEventListener(Event.RESIZE, onResize);
  38.             stage.addEventListener(MouseEvent.CLICK, onClick);
  39.             addEventListener(Event.ENTER_FRAME, onEnter);
  40.             
  41.         }
  42.         
  43.         private function onClick(e:MouseEvent):void 
  44.         {
  45.             main.change();
  46.         }
  47.         
  48.         private function onEnter(e:Event):void 
  49.         {
  50.             main.draw(mouseX, mouseY);
  51.         }
  52.         // りサイズ (未実装)
  53.         private function onResize(e:Event):void 
  54.         {
  55.             main.resize(stage.stageWidth, stage.stageHeight);
  56.         }
  57.     }
  58. }
  59. import flash.display.Bitmap;
  60. import flash.display.BitmapData;
  61. import flash.geom.ColorTransform;
  62. import flash.geom.Point;
  63. import flash.utils.ByteArray;
  64. class TestMain
  65. {
  66.     private var w: int;
  67.     private var h: int;
  68.     private var mw: int;
  69.     private var mh: int;
  70.     public var view: Bitmap;
  71.     private var bmpData: BitmapData;
  72.     private var forceMap: BitmapData;
  73.     private var randomSeed: int;
  74.     private var particles: Array = [];
  75.     private var num: int;
  76.     private var color: uint = 0xf0f0f0;
  77.     private var count: int = 0;
  78.     private var colorTr: ColorTransform;
  79.     
  80.     public function TestMain(w: int, h: int, numOfParticles: int)
  81.     {
  82.         this.w = w;
  83.         mw = w >> 1;
  84.         this.h = h;
  85.         mh = h >> 1;
  86.         bmpData = new BitmapData(w, h, false, 0x00000000);
  87.         forceMap = new BitmapData(mw, mh, false);
  88.         forceMap.perlinNoise(mw >> 1, mh >> 14, Math.random() * 0xFFFF, falsetrue3);
  89.         view = new Bitmap(bmpData);
  90.         num = numOfParticles;
  91.         var i: int;
  92.         var p: Particle;
  93.         while (i < num)
  94.         {
  95.             p = new Particle();
  96.             p.x = Math.random() * w;
  97.             p.y = Math.random() * h;
  98.             particles.push(p);
  99.             i++;
  100.         }
  101.         colorTr = new ColorTransform(1111, -32, -16, -16);
  102.     }
  103.     // 描画、マウスの判定を後で追加予定
  104.     public function draw(mouseX: Number, mouseY: Number): void
  105.     {
  106.         var i: int;
  107.         var p: Particle;
  108.         var col: uint;
  109.         bmpData.lock();
  110.         bmpData.colorTransform(bmpData.rect, colorTr);
  111.         while (i < num)
  112.         {
  113.             p = Particle(particles[i]);
  114.             //col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  115.                         col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  116.             p.vx = p.vx * 0.98 + (( col >> 16 & 0xff)-128) * 0.004;
  117.             p.vy = p.vy * 0.98 + (( col >> 8 & 0xff)-128) * 0.004;
  118.             p.x += p.vx;
  119.             p.y += p.vy;
  120.             if (p.x < 0) p.x += w;
  121.             else if (p.x >= w) p.x -= w;
  122.             if (p.y < 0) p.y += h;
  123.             else if (p.y >= h) p.y -= h;
  124.             bmpData.setPixel(p.x, p.y, color);
  125.             i++;
  126.         }
  127.         bmpData.unlock();
  128.     }
  129.     
  130.     public function change(): void
  131.     {
  132.         forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xFFFF, falsetrue7);
  133.     }
  134.     
  135.     public function resize(w: Number, h: Number): void
  136.     {
  137.         this.w = w;
  138.         this.h = h;
  139.         if (bmpData) 
  140.         {
  141.             bmpData.dispose();
  142.         }
  143.         bmpData = new BitmapData(w, h, false, 0x00000000);
  144.         view.bitmapData = bmpData;
  145.     }
  146. }
  147. class Particle
  148. {
  149.     public var x: Number = 0;
  150.     public var y: Number = 0;
  151.     public var vx: Number = 0;
  152.     public var vy: Number = 0;
  153.     
  154.     public function Particle()
  155.     {
  156.         
  157.     }
  158. }
noswf
  1. // forked from bkzen's 10万個ぱーてぃくる
  2. package {
  3.     import flash.display.Sprite;
  4.     import flash.display.StageAlign;
  5.     import flash.display.StageScaleMode;
  6.     import flash.events.Event;
  7.     import flash.events.MouseEvent;
  8.     import net.hires.debug.Stats;
  9.     
  10.     [SWF(backgroundColor = "0x000000", frameRate = "30")]
  11.     public class Test3 extends Sprite {
  12.         protected const NUM_OF_PARTICLES: int = 100000;
  13.         private var main: TestMain;
  14.         
  15.         public function Test3() {
  16.             if (stage) init();
  17.             else addEventListener(Event.ADDED_TO_STAGE, init);
  18.         }
  19.         
  20.         private function init(e:Event = null):void {
  21.             removeEventListener(Event.ADDED_TO_STAGE, init);
  22.             //
  23.             main = new TestMain(stage.stageWidth, stage.stageHeight, NUM_OF_PARTICLES);
  24.             addChild(main.view);
  25.             addChild(new Stats());
  26.             stage.scaleMode = StageScaleMode.NO_SCALE;
  27.             stage.align = StageAlign.TOP_LEFT;
  28.             stage.addEventListener(Event.RESIZE, onResize);
  29.             stage.addEventListener(MouseEvent.CLICK, onClick);
  30.             addEventListener(Event.ENTER_FRAME, onEnter);
  31.             
  32.         }
  33.         
  34.         private function onClick(e:MouseEvent):void {
  35.             main.change();
  36.         }
  37.         
  38.         private function onEnter(e:Event):void {
  39.             main.draw(mouseX, mouseY);
  40.         }
  41.          private function onResize(e:Event):void {
  42.             main.resize(stage.stageWidth, stage.stageHeight);
  43.         }
  44.     }
  45. }
  46. import flash.display.Bitmap;
  47. import flash.display.BitmapData;
  48. import flash.geom.ColorTransform;
  49. import flash.geom.Point;
  50. import flash.utils.ByteArray;
  51. import flash.filters.BlurFilter;
  52. class TestMain {
  53.     private var w: int;
  54.     private var h: int;
  55.     private var mw: int;
  56.     private var mh: int;
  57.     public var view: Bitmap;
  58.     private var bmpData: BitmapData;
  59.     private var forceMap: BitmapData;
  60.     private var randomSeed: int;
  61.     private var particles: Array = [];
  62.     private var num: int;
  63.     private var color: uint = 0xF0F0FF;
  64.     private var count: int = 0;
  65.     private var colorTr: ColorTransform;
  66.     
  67.     public function TestMain(w: int, h: int, numOfParticles: int){
  68.         this.w = w;
  69.         mw = w >> 1;
  70.         this.h = h;
  71.         mh = h >> 1;
  72.         bmpData = new BitmapData(w, h, false, 0x00000000);
  73.         forceMap = new BitmapData(mw, mh, false);
  74.         forceMap.perlinNoise(mw >> 1, mh >> 14, Math.random() * 0xFFFF, falsetrue3);
  75.         view = new Bitmap(bmpData);
  76.         num = numOfParticles;
  77.         var i: int;
  78.         var p: Particle;
  79.         while (i < num) {
  80.             p = new Particle();
  81.             p.x = Math.random() * w;
  82.             p.y = Math.random() * h;
  83.             particles.push(p);
  84.             i++;
  85.         }
  86.         colorTr = new ColorTransform(1111320, -2);
  87.     }
  88.      public function draw(mouseX: Number, mouseY: Number): void {
  89.         var i: int;
  90.         var p: Particle;
  91.         var col: uint;
  92.         bmpData.lock();
  93.         bmpData.colorTransform(bmpData.rect, colorTr);
  94.         while (i < num) {
  95.             p = Particle(particles[i]);
  96.             col = forceMap.getPixel(p.x >> 1, p.y >> 1);
  97.             p.vx = p.vx * 0.98 + (( col >> 16 & 0xff)-128) * 0.004;
  98.             p.vy = p.vy * 0.98 + (( col >> 8 & 0xff)-128) * 0.004;
  99.             p.x += p.vx;
  100.             p.y += p.vy;
  101.             if (p.x < 0) p.x += w;
  102.             else if (p.x >= w) p.x -= w;
  103.             if (p.y < 0) p.y += h;
  104.             else if (p.y >= h) p.y -= h;
  105.             bmpData.setPixel(p.x, p.y, color);
  106.             i++;
  107.         }
  108.         bmpData.unlock();
  109.         bmpData.applyFilter(bmpData, bmpData.rect, new Point(), new BlurFilter(16,16,1));
  110.     }
  111.     
  112.     public function change(): void {
  113.         forceMap.perlinNoise(mw, mh, 4, Math.random() * 0xFFFF, falsetrue7);
  114.     }
  115.     
  116.     public function resize(w: Number, h: Number): void {
  117.         this.w = w;
  118.         this.h = h;
  119.         if (bmpData) {
  120.             bmpData.dispose();
  121.         }
  122.         bmpData = new BitmapData(w, h, false, 0x00000000);
  123.         view.bitmapData = bmpData;
  124.     }
  125. }
  126. class Particle {
  127.     public var x: Number = 0;
  128.     public var y: Number = 0;
  129.     public var vx: Number = 0;
  130.     public var vy: Number = 0;
  131.     
  132.     public function Particle(){
  133.         
  134.     }
  135. }
noswf
Get Adobe Flash Player