Creating Static TV Noise in Flash using AS3

Creating Fast and Smooth Static TV Noise in Flash using AS3 was a simpler task than I expected it. First attempt was using for loops to set every pixel and was not very fast. A Simple browse through the API docs for BitmapData class gave me the 'noise' method

bgdata.noise(Math.random() * 1000, 0, 255, 7, true);
did the trick :)

Complete code below

package {
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Graphics;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
public class StaticNoise extends Sprite {
const ww = 480;
const hh = 272;
var bgdata:BitmapData = new BitmapData(ww, hh, false, 0xffffff);
var bg:Bitmap = new Bitmap(bgdata);
var zeroPt:Point = new Point(0,0);
public function StaticNoise() {
addChild(bg);
addEventListener(Event.ENTER_FRAME, drawBaby);
}
function drawBaby(e:Event) {
bgdata.lock();
bgdata.noise(Math.random() * 1000, 0, 255, 7, true);
bgdata.unlock();
}
}
}


You can modify,use this code where ever you want, without giving credits. But please just let me know in the comments if it helped you.

Comments

Popular posts from this blog

DoTween - The Big Demo

Download Android SDK standalone for offline installation

Adding a printer in VB.NET