as BitmapData類建立雜點效果

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.