/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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(); }