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

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

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


FORKED
  1. // forked from miniapp's Processingの流体サンプル
  2. /**
  3.  * 
  4.  * ここのをas3に書き換えたもの。
  5.  * http://processing.org/learning/topics/fluid.html
  6.  *
  7.  **/
  8. package {
  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.geom.Rectangle;
  16.     
  17.     [SWF(backgroundColor="0x0", width="465", height="465", frameRate="30")]
  18.     public class Main extends Sprite {
  19.         
  20.         public function Main():void {
  21.             if (stage) init();
  22.             else addEventListener(Event.ADDED_TO_STAGE, init);
  23.         }
  24.         
  25.         private var pmouseX:Number;
  26.         private var pmouseY:Number;
  27.         
  28.         private function init(e:Event = null):void {
  29.             removeEventListener(Event.ADDED_TO_STAGE, init);
  30.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  31.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  32.             stage.quality = StageQuality.MEDIUM;
  33.             
  34.             addChild(new Bitmap(canvas));
  35.             
  36.             lwidth = width / res;
  37.             lheight = height / res;
  38.             v = new Vector.<Vector.<vsquare>>(lheight + 1);
  39.             vbuf = new Vector.<Vector.<vbuffer>>(lheight + 1);
  40.             
  41.             for (var i:int = 0; i < pnum; i++) {
  42.                 p[i] = new particle(Math.random() * width, Math.random() * height);
  43.             }
  44.             
  45.             for (i = 0; i <= lwidth; i++) { 
  46.                 v[i] = new Vector.<vsquare>(lwidth + 1);
  47.                 vbuf[i] = new Vector.<vbuffer>(lwidth + 1);
  48.                 for (var u:int = 0; u <= lheight; u++) { 
  49.                     v[i][u] = new vsquare(i * res, u * res);
  50.                     vbuf[i][u] = new vbuffer(i * res, u * res);
  51.                 }
  52.                 
  53.                 v[i].fixed = true;//付け足し
  54.                 vbuf[i].fixed = true;//付け足し
  55.             }
  56.             
  57.             v.fixed = true;//付け足し
  58.             vbuf.fixed = true;//付け足し
  59.             
  60.             addEventListener(Event.ENTER_FRAME, draw);
  61.         }
  62.         
  63.         private function draw(e:Event):void {
  64.             mouseX = this.mouseX;
  65.             mouseY = this.mouseY;
  66.             
  67.             var axvel:int = mouseX - pmouseX;
  68.             var ayvel:int = mouseY - pmouseY;
  69.             
  70.             mouseXvel = (axvel != mouseXvel) ? axvel : 0;
  71.             mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;
  72.             
  73.             for (var i:int = 0; i < lwidth; i++) {
  74.                 for (var u:int = 0; u < lheight; u++) {
  75.                     vbuf[i][u].updatebuf(i, u);
  76.                     v[i][u].col = 32;
  77.                 }
  78.             }
  79.             for (i = 0; i < pnum-1; i++) {
  80.                 p[i].updatepos();
  81.             }
  82.             
  83.             canvas.lock();//付け足し
  84.             for (i = 0; i < lwidth; i++) {
  85.                 for (u = 0; u < lheight; u++) {
  86.                     v[i][u].addbuffer(i, u);
  87.                     v[i][u].updatevels(axvel, ayvel);
  88.                     v[i][u].display(i, u);
  89.                 }
  90.             }
  91.             canvas.unlock();//付け足し
  92.             
  93.             pmouseX = mouseX;
  94.             pmouseY = mouseY;
  95.         }
  96.         
  97.         private function mouseDownHandler(e:Event):void {
  98.             mousePressed = true;
  99.         }
  100.         
  101.         private function mouseUpHandler(e:Event):void {
  102.             mousePressed = false;
  103.         }
  104.     }
  105.     
  106. }
  107. import flash.display.BitmapData;
  108. var width:int = 500;
  109. var height:int = 500;
  110. var mousePressed:Boolean;
  111. var mouseX:Number = 0;
  112. var mouseY:Number = 0;
  113. var res:int = 5;
  114. var penSize:int = 30;
  115. var lwidth:int = 0;
  116. var lheight:int = 0;
  117. var pnum:int = 5000;
  118. var v:Vector.<Vector.<vsquare>>;
  119. var vbuf:Vector.<Vector.<vbuffer>>;
  120. var p:Vector.<particle> = new Vector.<particle>(pnum, true);
  121. var pcount:int = 0;
  122. var mouseXvel:int = 0;
  123. var mouseYvel:int = 0;
  124. var canvas:BitmapData = new BitmapData(width, height, false, 0x0);
  125. class particle{    
  126.     public function particle(xIn:Number, yIn:Number) {
  127.         x = xIn;
  128.         y = yIn;
  129.     }
  130.     
  131.     public var x:Number = 0;
  132.     public var y:Number = 0;
  133.     public var xvel:Number = 0;
  134.     public var yvel:Number = 0;
  135.     public var pos:int = 0;
  136.     
  137.     public function updatepos():void {
  138.         var col1:Number;
  139.         if (x > 0 && x < width && y > 0 && y < height) { 
  140.             var vi:int = int(x / res);
  141.             var vu:int = int(y / res);
  142.             var o:vsquare = v[vi][vu];
  143.             
  144.             var ax:Number = (x % res) / res;
  145.             var ay:Number = (y % res) / res;
  146.             
  147.             xvel += (1 - ax) * v[vi][vu].xvel * 0.05;
  148.             yvel += (1 - ay) * v[vi][vu].yvel * 0.05;
  149.             
  150.             xvel += ax * v[vi + 1][vu].xvel * 0.05;
  151.             yvel += ax * v[vi + 1][vu].yvel * 0.05;
  152.             
  153.             xvel += ay * v[vi][vu + 1].xvel * 0.05;
  154.             yvel += ay * v[vi][vu + 1].yvel * 0.05;
  155.             
  156.             o.col += 4;
  157.             
  158.             x += xvel;
  159.             y += yvel;
  160.         }
  161.         else {
  162.             x = Math.random() * width;
  163.             y = Math.random() * height;
  164.             xvel = 0;
  165.             yvel = 0;
  166.         }
  167.             
  168.         xvel *= 0.5;
  169.         yvel *= 0.5;
  170.         
  171.     }    
  172. }
  173. class vbuffer{
  174.         
  175.     public function vbuffer(xIn:int, yIn:int) {
  176.         x = xIn;
  177.         y = yIn;
  178.         pressurex = 0;
  179.         pressurey = 0;
  180.     }
  181.     
  182.     public var x:int = 0;
  183.     public var y:int = 0;
  184.     public var xvel:Number = 0;
  185.     public var yvel:Number = 0;
  186.     public var pressurex:Number = 0;
  187.     public var pressurey:Number = 0;
  188.     public var pressure:Number = 0;
  189.     
  190.     public function updatebuf(i:int, u:int):void {
  191.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  192.             pressurex = (v[i - 1][u - 1].xvel * 0.5 + v[i - 1][u].xvel + v[i - 1][u + 1].xvel * 0.5 - v[i + 1][u - 1].xvel * 0.5 - v[i + 1][u].xvel - v[i + 1][u + 1].xvel * 0.5);
  193.             pressurey = (v[i - 1][u - 1].yvel * 0.5 + v[i][u - 1].yvel + v[i + 1][u - 1].yvel * 0.5 - v[i - 1][u + 1].yvel * 0.5 - v[i][u + 1].yvel - v[i + 1][u + 1].yvel * 0.5);
  194.             pressure = (pressurex + pressurey) * 0.25;
  195.         }
  196.         
  197.     }
  198.     
  199. }
  200. import flash.geom.Rectangle;
  201. class vsquare{
  202.     
  203.     public function vsquare(xIn:int, yIn:int) {
  204.         x = xIn;
  205.         y = yIn;
  206.     }
  207.     
  208.     public var x:int = 0;
  209.     public var y:int = 0;
  210.     public var xvel:Number = 0;
  211.     public var yvel:Number = 0;
  212.     public var col:Number = 0;
  213.     
  214.     public function addbuffer(i:int, u:int):void {
  215.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  216.             xvel += (vbuf[i - 1][u - 1].pressure * 0.5
  217.             +vbuf[i - 1][u].pressure
  218.             +vbuf[i - 1][u + 1].pressure * 0.5
  219.             -vbuf[i + 1][u - 1].pressure * 0.5
  220.             -vbuf[i + 1][u].pressure
  221.             -vbuf[i + 1][u + 1].pressure * 0.5
  222.             ) * 0.25;
  223.             
  224.             yvel += (vbuf[i - 1][u - 1].pressure * 0.5
  225.             +vbuf[i][u - 1].pressure
  226.             +vbuf[i + 1][u - 1].pressure * 0.5
  227.             -vbuf[i - 1][u + 1].pressure * 0.5
  228.             -vbuf[i][u + 1].pressure
  229.             -vbuf[i + 1][u + 1].pressure * 0.5
  230.             ) * 0.25;
  231.             
  232.         }
  233.     }
  234.         
  235.     public function updatevels(mvelX:int, mvelY:int):void {
  236.         if (mousePressed) {
  237.             var adj:Number = x - mouseX;
  238.             var opp:Number = y - mouseY;
  239.             
  240.             var dist:Number = Math.sqrt(opp * opp + adj * adj);
  241.             if (dist < penSize) { 
  242.                 if (dist < 4) dist = penSize;
  243.                 var mod:Number = penSize / dist;
  244.                 xvel += mvelX * mod;
  245.                 yvel += mvelY * mod;
  246.             }
  247.         }
  248.         
  249.         xvel *= 0.99;
  250.         yvel *= 0.99;
  251.     }
  252.         
  253.     public function display(i:int, u:int):void {
  254.         var tcol:Number = 0;
  255.         
  256.         if (col > 255) col = 0;
  257.         if (i > 0 && i < lwidth - 1 && u > 0 && u < lheight - 1) { 
  258.             tcol = ( v[i][u + 1].col 
  259.             + v[i + 1][u].col
  260.             + v[i + 1][u + 1].col * 0.5
  261.             ) * 0.4;
  262.             tcol = int(tcol + col * 0.5);
  263.         }
  264.         else {
  265.             tcol = int(col);
  266.         }
  267.         
  268.         var coler:uint = tcol << 16 | tcol << 8 | tcol;
  269.         canvas.fillRect(new Rectangle(x, y, res, res), coler);
  270.     }
  271. }
noswf
  1. // forked from miniapp's Processingの流体サンプル
  2. /**
  3.  * 
  4.  * ここのをas3に書き換えたもの。
  5.  * http://processing.org/learning/topics/fluid.html
  6.  *
  7.  **/
  8. package {
  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.geom.Rectangle;
  16.     
  17.     [SWF(backgroundColor="0x0", width="465", height="465", frameRate="30")]
  18.     public class Main extends Sprite {
  19.         
  20.         public function Main():void {
  21.             if (stage) init();
  22.             else addEventListener(Event.ADDED_TO_STAGE, init);
  23.         }
  24.         
  25.         private var pmouseX:Number;
  26.         private var pmouseY:Number;
  27.         
  28.         private function init(e:Event = null):void {
  29.             removeEventListener(Event.ADDED_TO_STAGE, init);
  30.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  31.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  32.             stage.quality = StageQuality.MEDIUM;
  33.             
  34.             addChild(new Bitmap(canvas));
  35.             
  36.             lwidth = width / res;
  37.             lheight = height / res;
  38.             v = new Vector.<Vector.<vsquare>>(lheight + 1);
  39.             vbuf = new Vector.<Vector.<vbuffer>>(lheight + 1);
  40.             
  41.             for (var i:int = 0; i < pnum; i++) {
  42.                 p[i] = new particle(Math.random() * width, Math.random() * height);
  43.             }
  44.             
  45.             for (i = 0; i <= lwidth; i++) { 
  46.                 v[i] = new Vector.<vsquare>(lwidth + 1);
  47.                 vbuf[i] = new Vector.<vbuffer>(lwidth + 1);
  48.                 for (var u:int = 0; u <= lheight; u++) { 
  49.                     v[i][u] = new vsquare(i * res, u * res);
  50.                     vbuf[i][u] = new vbuffer(i * res, u * res);
  51.                 }
  52.                 
  53.                 v[i].fixed = true;//付け足し
  54.                 vbuf[i].fixed = true;//付け足し
  55.             }
  56.             
  57.             v.fixed = true;//付け足し
  58.             vbuf.fixed = true;//付け足し
  59.             
  60.             addEventListener(Event.ENTER_FRAME, draw);
  61.         }
  62.         
  63.         private function draw(e:Event):void {
  64.             mouseX = this.mouseX;
  65.             mouseY = this.mouseY;
  66.             
  67.             var axvel:int = mouseX - pmouseX;
  68.             var ayvel:int = mouseY - pmouseY;
  69.             
  70.             mouseXvel = (axvel != mouseXvel) ? axvel : 0;
  71.             mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;
  72.             
  73.             for (var i:int = 0; i < lwidth; i++) {
  74.                 for (var u:int = 0; u < lheight; u++) {
  75.                     vbuf[i][u].updatebuf(i, u);
  76.                     v[i][u].col = 32;
  77.                 }
  78.             }
  79.             for (i = 0; i < pnum-1; i++) {
  80.                 p[i].updatepos();
  81.             }
  82.             
  83.             canvas.lock();//付け足し
  84.             for (i = 0; i < lwidth; i++) {
  85.                 for (u = 0; u < lheight; u++) {
  86.                     v[i][u].addbuffer(i, u);
  87.                     v[i][u].updatevels(axvel, ayvel);
  88.                     v[i][u].display(i, u);
  89.                 }
  90.             }
  91.             canvas.unlock();//付け足し
  92.             
  93.             pmouseX = mouseX;
  94.             pmouseY = mouseY;
  95.         }
  96.         
  97.         private function mouseDownHandler(e:Event):void {
  98.             mousePressed = true;
  99.         }
  100.         
  101.         private function mouseUpHandler(e:Event):void {
  102.             mousePressed = false;
  103.         }
  104.     }
  105.     
  106. }
  107. import flash.display.BitmapData;
  108. var width:int = 400;
  109. var height:int = 400;
  110. var mousePressed:Boolean;
  111. var mouseX:Number = 0;
  112. var mouseY:Number = 0;
  113. var res:int = 5;
  114. var penSize:int = 50;
  115. var lwidth:int = 0;
  116. var lheight:int = 0;
  117. var pnum:int =10000;
  118. var v:Vector.<Vector.<vsquare>>;
  119. var vbuf:Vector.<Vector.<vbuffer>>;
  120. var p:Vector.<particle> = new Vector.<particle>(pnum, true);
  121. var pcount:int = 0;
  122. var mouseXvel:int = 0;
  123. var mouseYvel:int = 0;
  124. var canvas:BitmapData = new BitmapData(width, height, false, 0x0);
  125. class particle{    
  126.     public function particle(xIn:Number, yIn:Number) {
  127.         x = xIn;
  128.         y = yIn;
  129.     }
  130.     
  131.     public var x:Number = 0;
  132.     public var y:Number = 0;
  133.     public var xvel:Number = 0;
  134.     public var yvel:Number = 0;
  135.     public var pos:int = 0;
  136.     
  137.     public function updatepos():void {
  138.         var col1:Number;
  139.         if (x > 0 && x < width && y > 0 && y < height) { 
  140.             var vi:int = int(x / res);
  141.             var vu:int = int(y / res);
  142.             var o:vsquare = v[vi][vu];
  143.             
  144.             var ax:Number = (x % res) / res;
  145.             var ay:Number = (y % res) / res;
  146.             
  147.             xvel += (1 - ax) * v[vi][vu].xvel * 0.05;
  148.             yvel += (1 - ay) * v[vi][vu].yvel * 0.05;
  149.             
  150.             xvel += ax * v[vi + 1][vu].xvel * 0.05;
  151.             yvel += ax * v[vi + 1][vu].yvel * 0.05;
  152.             
  153.             xvel += ay * v[vi][vu + 1].xvel * 0.05;
  154.             yvel += ay * v[vi][vu + 1].yvel * 0.05;
  155.             
  156.             o.col += 4;
  157.             
  158.             x += xvel;
  159.             y += yvel;
  160.         }
  161.         else {
  162.             x = Math.random() * width;
  163.             y = Math.random() * height;
  164.             xvel = 0;
  165.             yvel = 0;
  166.         }
  167.             
  168.         xvel *= 0.5;
  169.         yvel *= 0.5;
  170.         
  171.     }    
  172. }
  173. class vbuffer{
  174.         
  175.     public function vbuffer(xIn:int, yIn:int) {
  176.         x = xIn;
  177.         y = yIn;
  178.         pressurex = 0;
  179.         pressurey = 0;
  180.     }
  181.     
  182.     public var x:int = 0;
  183.     public var y:int = 0;
  184.     public var xvel:Number = 0;
  185.     public var yvel:Number = 0;
  186.     public var pressurex:Number = 0;
  187.     public var pressurey:Number = 0;
  188.     public var pressure:Number = 0;
  189.     
  190.     public function updatebuf(i:int, u:int):void {
  191.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  192.             pressurex = (v[i - 1][u - 1].xvel * 0.5 + v[i - 1][u].xvel + v[i - 1][u + 1].xvel * 0.5 - v[i + 1][u - 1].xvel * 0.5 - v[i + 1][u].xvel - v[i + 1][u + 1].xvel * 0.5);
  193.             pressurey = (v[i - 1][u - 1].yvel * 0.5 + v[i][u - 1].yvel + v[i + 1][u - 1].yvel * 0.5 - v[i - 1][u + 1].yvel * 0.5 - v[i][u + 1].yvel - v[i + 1][u + 1].yvel * 0.5);
  194.             pressure = (pressurex + pressurey) * 0.25;
  195.         }
  196.         
  197.     }
  198.     
  199. }
  200. import flash.geom.Rectangle;
  201. class vsquare{
  202.     
  203.     public function vsquare(xIn:int, yIn:int) {
  204.         x = xIn;
  205.         y = yIn;
  206.     }
  207.     
  208.     public var x:int = 0;
  209.     public var y:int = 0;
  210.     public var xvel:Number = 0;
  211.     public var yvel:Number = 0;
  212.     public var col:Number = 0;
  213.     
  214.     public function addbuffer(i:int, u:int):void {
  215.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  216.             xvel += (vbuf[i - 1][u - 1].pressure * 0.5
  217.             +vbuf[i - 1][u].pressure
  218.             +vbuf[i - 1][u + 1].pressure * 0.5
  219.             -vbuf[i + 1][u - 1].pressure * 0.5
  220.             -vbuf[i + 1][u].pressure
  221.             -vbuf[i + 1][u + 1].pressure * 0.5
  222.             ) * 0.25;
  223.             
  224.             yvel += (vbuf[i - 1][u - 1].pressure * 0.5
  225.             +vbuf[i][u - 1].pressure
  226.             +vbuf[i + 1][u - 1].pressure * 0.5
  227.             -vbuf[i - 1][u + 1].pressure * 0.5
  228.             -vbuf[i][u + 1].pressure
  229.             -vbuf[i + 1][u + 1].pressure * 0.5
  230.             ) * 0.25;
  231.             
  232.         }
  233.     }
  234.         
  235.     public function updatevels(mvelX:int, mvelY:int):void {
  236.         if (mousePressed) {
  237.             var adj:Number = x - mouseX;
  238.             var opp:Number = y - mouseY;
  239.             
  240.             var dist:Number = Math.sqrt(opp * opp + adj * adj);
  241.             if (dist < penSize) { 
  242.                 if (dist < 4) dist = penSize;
  243.                 var mod:Number = penSize / dist;
  244.                 xvel += mvelX * mod;
  245.                 yvel += mvelY * mod;
  246.             }
  247.         }
  248.         
  249.         xvel *= 0.99;
  250.         yvel *= 0.99;
  251.     }
  252.         
  253.     public function display(i:int, u:int):void {
  254.         var tcol:Number = 0;
  255.         
  256.         if (col > 255) col = 255;
  257.         if (i > 0 && i < lwidth - 1 && u > 0 && u < lheight - 1) { 
  258.             tcol = ( v[i][u + 1].col 
  259.             + v[i + 1][u].col
  260.             + v[i + 1][u + 1].col * 0.5
  261.             ) * 0.4;
  262.             tcol = int(tcol + col * 0.5);
  263.         }
  264.         else {
  265.             tcol = int(col);
  266.         }
  267.         
  268.         var coler:uint = tcol << 16 | tcol << 8 | tcol;
  269.         canvas.fillRect(new Rectangle(x, y, res, res), coler);
  270.     }
  271. }
noswf
  1. // forked from miniapp's Processingの流体サンプル
  2. /**
  3.  * 
  4.  * ここのをas3に書き換えたもの。
  5.  * http://processing.org/learning/topics/fluid.html
  6.  *
  7.  **/
  8. package {
  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.geom.Rectangle;
  16.     
  17.     [SWF(backgroundColor="0x0", width="465", height="465", frameRate="30")]
  18.     public class Main extends Sprite {
  19.         
  20.         public function Main():void {
  21.             if (stage) init();
  22.             else addEventListener(Event.ADDED_TO_STAGE, init);
  23.         }
  24.         
  25.         private var pmouseX:Number;
  26.         private var pmouseY:Number;
  27.         
  28.         private function init(e:Event = null):void {
  29.             removeEventListener(Event.ADDED_TO_STAGE, init);
  30.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  31.             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  32.             stage.quality = StageQuality.MEDIUM;
  33.             
  34.             addChild(new Bitmap(canvas));
  35.             
  36.             lwidth = width / res;
  37.             lheight = height / res;
  38.             v = new Vector.<Vector.<vsquare>>(lheight + 1);
  39.             vbuf = new Vector.<Vector.<vbuffer>>(lheight + 1);
  40.             
  41.             for (var i:int = 0; i < pnum; i++) {
  42.                 p[i] = new particle(Math.random() * width, Math.random() * height);
  43.             }
  44.             
  45.             for (i = 0; i <= lwidth; i++) { 
  46.                 v[i] = new Vector.<vsquare>(lwidth + 1);
  47.                 vbuf[i] = new Vector.<vbuffer>(lwidth + 1);
  48.                 for (var u:int = 0; u <= lheight; u++) { 
  49.                     v[i][u] = new vsquare(i * res, u * res);
  50.                     vbuf[i][u] = new vbuffer(i * res, u * res);
  51.                 }
  52.                 
  53.                 v[i].fixed = true;//付け足し
  54.                 vbuf[i].fixed = true;//付け足し
  55.             }
  56.             
  57.             v.fixed = true;//付け足し
  58.             vbuf.fixed = true;//付け足し
  59.             
  60.             addEventListener(Event.ENTER_FRAME, draw);
  61.         }
  62.         
  63.         private function draw(e:Event):void {
  64.             mouseX = this.mouseX;
  65.             mouseY = this.mouseY;
  66.             
  67.             var axvel:int = mouseX - pmouseX;
  68.             var ayvel:int = mouseY - pmouseY;
  69.             
  70.             mouseXvel = (axvel != mouseXvel) ? axvel : 0;
  71.             mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;
  72.             
  73.             for (var i:int = 0; i < lwidth; i++) {
  74.                 for (var u:int = 0; u < lheight; u++) {
  75.                     vbuf[i][u].updatebuf(i, u);
  76.                     v[i][u].col = 32;
  77.                 }
  78.             }
  79.             for (i = 0; i < pnum-1; i++) {
  80.                 p[i].updatepos();
  81.             }
  82.             
  83.             canvas.lock();//付け足し
  84.             for (i = 0; i < lwidth; i++) {
  85.                 for (u = 0; u < lheight; u++) {
  86.                     v[i][u].addbuffer(i, u);
  87.                     v[i][u].updatevels(axvel, ayvel);
  88.                     v[i][u].display(i, u);
  89.                 }
  90.             }
  91.             canvas.unlock();//付け足し
  92.             
  93.             pmouseX = mouseX;
  94.             pmouseY = mouseY;
  95.         }
  96.         
  97.         private function mouseDownHandler(e:Event):void {
  98.             mousePressed = true;
  99.         }
  100.         
  101.         private function mouseUpHandler(e:Event):void {
  102.             mousePressed = false;
  103.         }
  104.     }
  105.     
  106. }
  107. import flash.display.BitmapData;
  108. var width:int = 200;
  109. var height:int = 200;
  110. var mousePressed:Boolean;
  111. var mouseX:Number = 0;
  112. var mouseY:Number = 0;
  113. var res:int = 5;
  114. var penSize:int = 30;
  115. var lwidth:int = 0;
  116. var lheight:int = 0;
  117. var pnum:int = 7000;
  118. var v:Vector.<Vector.<vsquare>>;
  119. var vbuf:Vector.<Vector.<vbuffer>>;
  120. var p:Vector.<particle> = new Vector.<particle>(pnum, true);
  121. var pcount:int = 0;
  122. var mouseXvel:int = 0;
  123. var mouseYvel:int = 0;
  124. var canvas:BitmapData = new BitmapData(width, height, false, 0x0);
  125. class particle{    
  126.     public function particle(xIn:Number, yIn:Number) {
  127.         x = xIn;
  128.         y = yIn;
  129.     }
  130.     
  131.     public var x:Number = 0;
  132.     public var y:Number = 0;
  133.     public var xvel:Number = 0;
  134.     public var yvel:Number = 0;
  135.     public var pos:int = 0;
  136.     
  137.     public function updatepos():void {
  138.         var col1:Number;
  139.         if (x > 0 && x < width && y > 0 && y < height) { 
  140.             var vi:int = int(x / res);
  141.             var vu:int = int(y / res);
  142.             var o:vsquare = v[vi][vu];
  143.             
  144.             var ax:Number = (x % res) / res;
  145.             var ay:Number = (y % res) / res;
  146.             
  147.             xvel += (1 - ax) * v[vi][vu].xvel * 0.05;
  148.             yvel += (1 - ay) * v[vi][vu].yvel * 0.05;
  149.             
  150.             xvel += ax * v[vi + 1][vu].xvel * 0.05;
  151.             yvel += ax * v[vi + 1][vu].yvel * 0.05;
  152.             
  153.             xvel += ay * v[vi][vu + 1].xvel * 0.05;
  154.             yvel += ay * v[vi][vu + 1].yvel * 0.05;
  155.             
  156.             o.col += 4;
  157.             
  158.             x += xvel;
  159.             y += yvel;
  160.         }
  161.         else {
  162.             x = Math.random() * width;
  163.             y = Math.random() * height;
  164.             xvel = 0;
  165.             yvel = 0;
  166.         }
  167.             
  168.         xvel *= 0.5;
  169.         yvel *= 0.5;
  170.         
  171.     }    
  172. }
  173. class vbuffer{
  174.         
  175.     public function vbuffer(xIn:int, yIn:int) {
  176.         x = xIn;
  177.         y = yIn;
  178.         pressurex = 0;
  179.         pressurey = 0;
  180.     }
  181.     
  182.     public var x:int = 0;
  183.     public var y:int = 0;
  184.     public var xvel:Number = 0;
  185.     public var yvel:Number = 0;
  186.     public var pressurex:Number = 0;
  187.     public var pressurey:Number = 0;
  188.     public var pressure:Number = 0;
  189.     
  190.     public function updatebuf(i:int, u:int):void {
  191.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  192.             pressurex = (v[i - 1][u - 1].xvel * 0.5 + v[i - 1][u].xvel + v[i - 1][u + 1].xvel * 0.5 - v[i + 1][u - 1].xvel * 0.5 - v[i + 1][u].xvel - v[i + 1][u + 1].xvel * 0.5);
  193.             pressurey = (v[i - 1][u - 1].yvel * 0.5 + v[i][u - 1].yvel + v[i + 1][u - 1].yvel * 0.5 - v[i - 1][u + 1].yvel * 0.5 - v[i][u + 1].yvel - v[i + 1][u + 1].yvel * 0.5);
  194.             pressure = (pressurex + pressurey) * 0.25;
  195.         }
  196.         
  197.     }
  198.     
  199. }
  200. import flash.geom.Rectangle;
  201. class vsquare{
  202.     
  203.     public function vsquare(xIn:int, yIn:int) {
  204.         x = xIn;
  205.         y = yIn;
  206.     }
  207.     
  208.     public var x:int = 0;
  209.     public var y:int = 0;
  210.     public var xvel:Number = 0;
  211.     public var yvel:Number = 0;
  212.     public var col:Number = 0;
  213.     
  214.     public function addbuffer(i:int, u:int):void {
  215.         if (i > 0 && i < lwidth && u > 0 && u < lheight) { 
  216.             xvel += (vbuf[i - 1][u - 1].pressure * 0.5
  217.             +vbuf[i - 1][u].pressure
  218.             +vbuf[i - 1][u + 1].pressure * 0.5
  219.             -vbuf[i + 1][u - 1].pressure * 0.5
  220.             -vbuf[i + 1][u].pressure
  221.             -vbuf[i + 1][u + 1].pressure * 0.5
  222.             ) * 0.25;
  223.             
  224.             yvel += (vbuf[i - 1][u - 1].pressure * 0.5
  225.             +vbuf[i][u - 1].pressure
  226.             +vbuf[i + 1][u - 1].pressure * 0.5
  227.             -vbuf[i - 1][u + 1].pressure * 0.5
  228.             -vbuf[i][u + 1].pressure
  229.             -vbuf[i + 1][u + 1].pressure * 0.5
  230.             ) * 0.25;
  231.             
  232.         }
  233.     }
  234.         
  235.     public function updatevels(mvelX:int, mvelY:int):void {
  236.         if (mousePressed) {
  237.             var adj:Number = x - mouseX;
  238.             var opp:Number = y - mouseY;
  239.             
  240.             var dist:Number = Math.sqrt(opp * opp + adj * adj);
  241.             if (dist < penSize) { 
  242.                 if (dist < 4) dist = penSize;
  243.                 var mod:Number = penSize / dist;
  244.                 xvel += mvelX * mod;
  245.                 yvel += mvelY * mod;
  246.             }
  247.         }
  248.         
  249.         xvel *= 0.99;
  250.         yvel *= 0.99;
  251.     }
  252.         
  253.     public function display(i:int, u:int):void {
  254.         var tcol:Number = 0;
  255.         
  256.         if (col > 255) col = 255;
  257.         if (i > 0 && i < lwidth - 1 && u > 0 && u < lheight - 1) { 
  258.             tcol = ( v[i][u + 1].col 
  259.             + v[i + 1][u].col
  260.             + v[i + 1][u + 1].col * 0.5
  261.             ) * 0.4;
  262.             tcol = int(tcol + col * 0.5);
  263.         }
  264.         else {
  265.             tcol = int(col);
  266.         }
  267.         
  268.         var coler:uint = tcol << 16 | tcol << 8 | tcol;
  269.         canvas.fillRect(new Rectangle(x, y, res, res), coler);
  270.     }
  271. }
noswf
Get Adobe Flash Player