建立一個新的 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("yun_qi_img/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() 方法效果和置換圖濾鏡來使動態載入的映像扭曲。下面的過程將顯示這一效果。