Return to Snippet

Revision: 25932
at April 14, 2010 09:25 by adrianparr


Initial Code
var imgData:BitmapData = new BitmapData(550, 400, false, 0x000000);
var bmp:Bitmap = new Bitmap(imgData);

fillBitmapDataWithRandomPixels(imgData);
blackAndWhite(bmp, true);
addChild(bmp);

var myTimer:Timer = new Timer(50);
myTimer.addEventListener(TimerEvent.TIMER, onMyTimer_TIMER);
myTimer.start();

function onMyTimer_TIMER(event:TimerEvent):void {
	fillBitmapDataWithRandomPixels(imgData);
}

function blackAndWhite($target:DisplayObject, $enabled:Boolean):void
{
	var rc:Number = 1/3;
	var gc:Number = 1/3;
	var bc:Number = 1/3;
	var cmf:ColorMatrixFilter = new ColorMatrixFilter([rc, gc, bc, 0, 0, rc, gc, bc, 0, 0, rc, gc, bc, 0, 0, 0, 0, 0, 1, 0]);

	if ($enabled) {
		$target.filters = [cmf];
	} else {
		$target.filters = [];
	}
}

function fillBitmapDataWithRandomPixels($bmp:BitmapData):void {
	$bmp.lock();
	var colour:uint;
	for (var i:int = 0; i < $bmp.height ; i++) {
		for (var j:int = 0; j < $bmp.width; j++) {
			colour = Math.random() * 0xFFFFFF;
			$bmp.setPixel(j, i, colour);
		}
	}
	imgData.unlock();
}

Initial URL


Initial Description


Initial Title
AS3 Create a TV Static Type Effect Using SetPixel

Initial Tags
color

Initial Language
ActionScript 3