Create a new Flash document and save it as a noise.fla.
Add the following ActionScript to frame 1th of the timeline: import Flash.display.BitmapData;
The code is as follows |
Copy Code |
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 = * _xmouse/stage.width; var high:number = * _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); } |
This code uses the instance name Status_txt to create a text field that follows the mouse pointer and displays the current value of the high and low parameters for the noise () method. The SetInterval () function changes the clutter effect, and the clutter effect is updated every 100 milliseconds (1/10) of the Updatenoise () function by successive calls to it. The high and low parameters of the noise () method are determined by calculating the current position of the pointer on the stage.
Select Control > Test movie to test the document.
Moving the mouse pointer along the x-axis affects the low parameter, while moving the mouse pointer along the y-axis affects the high parameter.
The BitmapData class also allows you to distort dynamically loaded images by combining the Perlinnoise () method effect and the displacement map filter. The following procedure shows this effect.