一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

as BitmapData类创建杂点效果

时间:2013-05-13 编辑:简简单单 来源:一聚教程网

创建一个新的 Flash 文档,并将其保存为 noise.fla。
    将下面的 ActionScript 添加到时间轴的第 1 帧: import flash.display.BitmapData;

 代码如下 复制代码
this.createTextField("status_txt", 90, 0, 0, 100, 20);
status_txt.selectable = false;
status_txt.background = 0xFFFFFF;
status_txt.autoSize = "left";
function onMouseMove() {
    status_txt._x = _xmouse;
    status_txt._y = _ymouse-20;
    updateAfterEvent();
}
this.createEmptyMovieClip("img_mc", 10);
img_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
var noiseBmp:BitmapData = new BitmapData(Stage.width, Stage.height, true);
this.attachBitmap(noiseBmp, 20);
setInterval(updateNoise, 100);
var grayScale:Boolean = true;
function updateNoise():Void {
    var low:Number = 30 * _xmouse / Stage.width;
    var high:Number = 200 * _ymouse / Stage.height;
    status_txt.text = "low:" + Math.round(low) + ", high:" + Math.round(high);
    noiseBmp.noise(Math.round(Math.random() * 100000), low, high, 8, true);
}


    此代码使用实例名称 status_txt 创建一个文本字段,该字段跟随鼠标指针并为 noise() 方法显示 high 和 low 参数的当前值。setInterval() 函数可更改杂点效果,杂点效果通过连续调用 updateNoise() 函数每隔 100 毫秒(一秒的 1/10)更新一次。noise() 方法的 high 和 low 参数通过计算指针在舞台上的当前位置来确定。

    选择"控制">"测试影片"来测试该文档。
沿 x 轴移动鼠标指针将影响 low 参数;而沿 y 轴移动鼠标指针将影响 high 参数。

    BitmapData 类还允许您通过结合使用 perlinNoise() 方法效果和置换图滤镜来使动态加载的图像扭曲。下面的过程将显示这一效果。

热门栏目