Water Pool wanson forked:7favorite:39lines:114license : All rights reserved modified : 2009-02-02 19:50:09 Embed Tweet // write as3 code here.. package { import flash.display.*; import flash.events.Event; [SWF(width="300", height="300", backgroundColor="0x000000", frameRate="30")] public class Program extends Sprite { private var demo:Demo; public function Program() { addEventListener(Event.ENTER_FRAME, onEnterFrame); demo = new Demo(this); } public function onEnterFrame(ev:Event):void { demo.frame(); } } } import flash.display.*; import flash.events.MouseEvent; class Demo { private var bmpdata:BitmapData; private var field1:Array = []; private var field2:Array = []; private const SIZEX:int = 100; private const SIZEY:int = 100; private const FSIZEX:int = SIZEX + 2; private const FSIZEY:int = SIZEY + 2; private const SCALE:int = 3; private var ox:int; private var oy:int; private const c1:Number = 0.5; private const c2:Number = 0.005; private const cc:Number = 1 / (1 + c2); private var filters:Array; public function Demo(screen:Sprite) { screen.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); bmpdata = new BitmapData(SIZEX, SIZEY); var mapimg:Bitmap = new Bitmap(bmpdata); mapimg.scaleX = mapimg.scaleY = SCALE; screen.addChild(mapimg); var i:uint; var j:uint; for (i = 0; i < FSIZEY; ++i) { field1.push([]); field2.push([]); for (j = 0; j < FSIZEX; ++j) field1[i][j] = 0.0; } // initialize for (i = 0; i < FSIZEX; i++) field1[0][i] = field1[FSIZEY - 1][i] = field2[0][i] = field2[FSIZEY - 1][i] = 0.0; for (i = 0; i < FSIZEY; i++) field1[i][0] = field1[i][FSIZEX - 1] = field2[i][0] = field2[i][FSIZEX - 1] = 0.0; for (i = 1; i < FSIZEY - 1; ++i) for (j = 1; j < FSIZEX - 1; ++j) field2[i][j] = field1[i][j] + 0.25 * (field1[i+1][j] + field1[i-1][j] + field1[i][j+1] + field1[i][j-1] - 4 * field1[i][j]); put(50, 50, 300); } private function onMouseMove(ev:MouseEvent):void { put((ev.localX + 1) / SCALE, (ev.localY + 1) / SCALE, 15); } private function put(px:Number, py:Number, pow:Number):void { const r:uint = 10; const bx:int = (px - r < 1) ? 1 : px - r; const ex:int = (px + r > FSIZEX - 1) ? FSIZEX - 1 : px + r; const by:int = (py - r < 1) ? 1 : py - r; const ey:int = (py + r > FSIZEY - 1) ? FSIZEY - 1 : py + r; for (var y:uint = by; y < ey; ++y) { for (var x:uint = bx; x < ex; ++x) { const d:Number = Math.sqrt((px - x) * (px - x) + (py - y) * (py - y)); if (d < r) { var p:Number = pow * Math.cos(Math.PI / 2 * d / r); field1[y][x] += p; field2[y][x] += p; } } } } public function frame():void { // draw var r:uint, g:uint, b:uint, c:uint; var x:uint, y:uint; var line_c:Array, line_p:Array, line_n:Array; bmpdata.lock(); for (y = 1; y < SIZEY + 1; ++y) { line_c = field2[y]; for (x = 1; x < SIZEX + 1; ++x) { c = Math.abs(line_c[x]); r = c + 140; g = c + 160; b = c + 220; if (r > 255) r = 255; if (g > 255) g = 255; if (b > 255) b = 255; bmpdata.setPixel(x - 1, y - 1, (r << 16) + (g << 8) + b); } } bmpdata.unlock(); // step for (y = 1; y < FSIZEY - 1; ++y) { line_p = field2[y - 1]; line_c = field2[y]; line_n = field2[y + 1]; for (x = 1; x < FSIZEX - 1; ++x) { field1[y][x] = (line_c[x] * (2 - 4 * c1) - field1[y][x] * (1 - c2) + c1 * (line_n[x] + line_p[x] + line_c[x + 1] + line_c[x - 1])) * cc; } } // next const tmp:Array = field1; field1 = field2; field2 = tmp; } } Code Fullscreen Preview Fullscreen NKT ProjectNya publicroots kevinlin kuroarizuka jyyender NaoHachi ug24k8 IPFix Mae_ITR Giggle FlashFit Lowmid neco yamat fallen McInerney hanaoka AM300 M4RC0 twistcube Kallethyseli.. twelvetoes yoshifuto resense tkinjo Kay RoundRoom zahir nsos : I like it bradsedito : Beuatifl bobjoker : graphics 123123123 : liquidparticlewater hioki : BitmapData波動 simpleex : liquidwater t_matsuda : graphicsliquid spog : Waves2 stinger79 : water mnordine : unko's pool BitmapData graphics liquid particle water localY Math.pow localX scaleY filters scaleX unlock lock setPixel MouseEvent.MOUSE_MOVE frame MouseEvent.ENTER_FRAME Math.abs Math.sqrt addEventListener MouseEvent push Math.PI Math.cos addChild sort new page view favorite forked pv151 forked from: Water Pool yanezaki forked:0 favorite:0lines:114 (diff:2) pv154 forked from: Water Pool gyaran009 forked:0 favorite:0lines:114 (diff:1) pv232 forked from: Water Pool postleswait forked:0 favorite:0lines:114 (diff:1) pv260 forked from: Water Pool hacker_62yazx2n forked:0 favorite:0lines:114 (diff:1) pv0 forked from: Water Pool hacker_u3ut1hxr forked:0 favorite:0lines:114 (diff:1) pv4609 水面。画像がゆがむはずだが・・・ siba2260 forked:6 favorite:3lines:137 (diff:274) pv4155 forked from: Water Pool minon forked:11 favorite:29lines:140 (diff:40) tag: AS3 Class DisplacementMapFilter Water bitmap effect noise