water
...
@author lizhi
/**
* Copyright lizhi ( http://wonderfl.net/user/lizhi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ikUq
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.getTimer;
/**
* ...
* @author lizhi
*/
public class TestWater extends Sprite
{
private var b:BitmapData;
private var bc:BitmapData;
public function TestWater()
{
b = new BitmapData(200, 200, false);
for (var i:int = 0; i < b.height; i++){
for (var k:int = 0; k < b.width; k++){
b.setPixel(k,i, (i^k)<<16 | (i ^ k) << 8 | (i^k));
}
}
bc = b.clone();
addChild(new Bitmap(b));
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function enterFrame(e:Event):void
{
var t:Number = getTimer()/400;
var scale:Number = 4;
var wave:Number = Math.PI * 6 / b.height;
b.lock();
for (var x:int = 0; x < b.width;x++ ) {
for (var y:int = 0; y < b.height; y++ ) {
var offsetX:Number = Math.sin(y*wave+t)*scale+Math.sin(y*wave*.7+t*2.4)*scale;
var offsetY:Number = Math.sin(x*wave+t)*scale+Math.sin(x*wave*1.4+t*4.4)*scale;
b.setPixel(x, y, bc.getPixel(x+offsetX,y+offsetY));
}
}
b.unlock();
}
}
}