Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Creating fine-grained noise dynamically is computationally expensive, so I generate low-res noise and scale it up. In your project, simply add the bitmap setup code after the addEventListener call and then add the single line to generate the noise to your activity loop.</p> <pre><code>package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Sprite; import flash.events.Event; import flash.geom.Matrix; import flash.media.Camera; import flash.media.Video; import flash.utils.getTimer; public class NoiseMain extends Sprite { protected static const VID_WIDTH : uint = 640; protected static const VID_HEIGHT : uint = 480; protected static const NOISE_SCALE_X : Number = 4; protected static const NOISE_SCALE_Y : Number = 2; protected var _vid : Video; protected var _noise : BitmapData; protected var _composite : BitmapData; protected var _matrix : Matrix; public function NoiseMain() { // We're creating a webcam outlet, but not adding it to the stage since we want to post-process the image. _vid = new Video(VID_WIDTH, VID_HEIGHT); var cam : Camera = Camera.getCamera(); cam.setMode(VID_WIDTH, VID_HEIGHT, 30); _vid.attachCamera(cam); var w : uint = Math.ceil(VID_WIDTH / NOISE_SCALE_X); var h : uint = Math.ceil(VID_HEIGHT / NOISE_SCALE_Y); _noise = new BitmapData(w, h, false, 0xFFFFFF); _composite = new BitmapData(VID_WIDTH, VID_HEIGHT, false, 0x000000); var bmp : Bitmap = new Bitmap(_composite); addChild(bmp); _matrix = new Matrix(NOISE_SCALE_X, 0, 0, NOISE_SCALE_Y); stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler); } protected function enterFrameHandler(evt : Event) : void { _noise.noise(getTimer(), 204, 255, 7, true); _composite.lock(); _composite.draw(_vid); _composite.draw(_noise, _matrix, null, BlendMode.MULTIPLY); _composite.unlock(); } } } </code></pre> <p>EDIT: I've revised my example to be more in line with what you're trying to do. You can tweak the noise scale constants to change the "texture" of the noise as well as messing with the strength of the noise (the 2nd and 3rd arguments to the noise() method) and the visual appearance of the noise by changing the BlendMode in the 2nd draw() call).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload