Apr 3, 2008
For my current project at firstborn, I had to create an animated ocean view with actionscript. My solution uses a combination of BitmapData, PerlinNoise and DisplacementMapFilter to apply this water effect to a static JPG-Image. Since the project is still ongoing, I didn't find the time yet to properly document the code so all I'm going to post here for now is the two actionscript functions, responsible for the effect you see above. The full class, and a little demonstration of which values you have to change to achieve certain effects will follow soon.
private function initWaterFX():void { waterBmp = new BitmapData(waterData.water.@width, waterData.water.@height); pt = new Point(0,0); mpoint = new Point(0,0); waterDispl = new DisplacementMapFilter(waterBmp, mpoint, 1, 2, 10, 31, DisplacementMapFilterMode.IGNORE); filterList = new Array(); filterList.push(waterDispl); addEventListener(Event.ENTER_FRAME, renderFx); } private function renderFx(event:Event):void { offset.y = i/12; offset.x = i/24; waterBmp.perlinNoise(40, 6, 2, 50, true, false, 7, true, [offset]); water.filters = filterList; i++; }
