[Actionscript3] 纯文本查看 复制代码
import flash.display.BitmapData;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.Bitmap;
var bgShape: Shape = new Shape();
var matrix: Matrix = new Matrix();
matrix.createGradientBox(1280, 960, 0, -320, -240);
bgShape.graphics.beginGradientFill(GradientType.RADIAL, [0x220045, 0x000000], [1, 1], [0, 255], matrix);
bgShape.graphics.drawRect(0, 0, 640, 480);
bgShape.graphics.endFill();
var bgBd: BitmapData = new BitmapData(720, 480, false, 0x000000);
bgBd.draw(bgShape);
addChild(new Bitmap(bgBd));
var waterBm: Bitmap = new Bitmap();
waterBm.blendMode = BlendMode.HARDLIGHT;
waterBm.y = 200;
var waterBd_vec: Vector. < BitmapData > = new Vector. < BitmapData > (72, true);
addChild(waterBm);
var t: int = 0;
var offsets: Array = [];
offsets[0] = new Point();
offsets[1] = new Point();
var fadeOutShape: Shape = new Shape();
var fadeOutMatrix: Matrix = new Matrix();
fadeOutMatrix.createGradientBox(720, 280, Math.PI * 0.5);
fadeOutShape.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0x000000], [0, 1], [0, 20], fadeOutMatrix);
fadeOutShape.graphics.drawRect(0, 0, 720, 280);
fadeOutShape.graphics.endFill();
var fadeOutBd: BitmapData = new BitmapData(720, 280, true, 0x00000000);
fadeOutBd.draw(fadeOutShape);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
var seed: uint = new Date().time;
function enterFrameHandler(event: Event): void
{
var waterBd: BitmapData = waterBd_vec[t];
if (waterBd == null)
{
waterBd = new BitmapData(720, 280, true, 0x00000000);
offsets[0].x = t * 10;
waterBd.perlinNoise(80, 10, 8, seed, true, true, BitmapDataChannel.RED, true, offsets);
waterBd.copyPixels(waterBd, waterBd.rect, new Point(), fadeOutBd);
waterBd.colorTransform(waterBd.rect, new ColorTransform(1, 1, 1, 0.7));
waterBd_vec[t] = waterBd;
}
waterBm.bitmapData = waterBd;
t = (t + 1) % 72;
}