打开Macromedia Flash 8.0
一、设置舞台大小(380×175)。
二、导入图片到库,不要导入到舞台。
三、打开库设置图片链接。标识符为:surface ,将“为运行时导入”勾去掉,勾上“为actionscript 导出”和“在第一帧导出”
四、在第一帧插入动作代码(按F9,把下列代码粘贴进去即可)
var damper = new flash.display.BitmapData(380, 175, false, 128);
var result = new flash.display.BitmapData(380, 175, false, 128);
var result2 = new flash.display.BitmapData(380, 175, false, 128);
var source = new flash.display.BitmapData(380, 175, false, 128);
var buffer = new flash.display.BitmapData(380, 175, false, 128);
var output = new flash.display.BitmapData(380, 175, true, 128);
var surface = flash.display.BitmapData.loadBitmap("surface");
var bounds = new flash.geom.Rectangle(0, 0, 380, 175);
var origin = new flash.geom.Point();
var matrix = new flash.geom.Matrix();
var matrix2 = new flash.geom.Matrix();
matrix2.a = matrix2.d = 2;
var wave = new flash.filters.ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);
var damp = new flash.geom.ColorTransform(0, 0, 9.960937E-001, 1, 0, 0, 2, 0);
var water = new flash.filters.DisplacementMapFilter(result2, origin, 4, 4, 48, 48, "ignore");
attachBitmap(output, 0);
var ms = getTimer();
var frame = 0;
var mouseDown = false;
onMouseDown = function ()
{
mouseDown = true;
};
onMouseUp = function ()
{
onEnterFrame();
mouseDown = false;
};
onEnterFrame = function ()
{
if (mouseDown)
{
var _loc2 = _xmouse / 2;
var _loc1 = _ymouse / 2;
source.setPixel(_loc2 + 1, _loc1, 16777215);
source.setPixel(_loc2 - 1, _loc1, 16777215);
source.setPixel(_loc2, _loc1 + 1, 16777215);
source.setPixel(_loc2, _loc1 - 1, 16777215);
source.setPixel(_loc2, _loc1, 16777215);
} // end if
result.applyFilter(source, bounds, origin, wave);
result.draw(result, matrix, null, "add");
result.draw(buffer, matrix, null, "difference");
result.draw(result, matrix, damp);
result2.draw(result, matrix2, null, null, null, true);
output.applyFilter(surface, new flash.geom.Rectangle(0, 0, 380, 175), origin, water);
buffer = source;
source = result.clone();
};
五、把帧频提高点(默认为12)
六、测试影片,呵呵,水波涟漪,真实再现,赶快试试吧!
七、效果演示: