package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.Event; import flash.utils.getTimer; import flash.text.TextField; public class BufferTest6 extends Sprite { public static const STAGE_WIDTH:int = 800; public static const STAGE_HEIGHT:int = 600; private var outputBitmapData:BitmapData; private var outputBitmap:Bitmap; private var t:Number; private var dt:Number = .01; private var frameTimeTxt:TextField; public function BufferTest6() { outputBitmapData = new BitmapData(STAGE_WIDTH, STAGE_HEIGHT, false); outputBitmap = new Bitmap(outputBitmapData); addChild(outputBitmap); frameTimeTxt = new TextField(); frameTimeTxt.x = 8; frameTimeTxt.y = 8; frameTimeTxt.textColor = 0xFFFFFF; addChild(frameTimeTxt); t = 0; addEventListener(Event.ENTER_FRAME, update, false, 0, true); } public function update(e:*) { var timer:Number = getTimer(); t += dt; var x:int; var y:int; var r:int; var g:int; var b:int; outputBitmapData.lock(); for(x = 0; x < STAGE_WIDTH; ++x) { for(y = 0; y < STAGE_HEIGHT; ++y) { r = (t*100 + 255 * x / STAGE_WIDTH)%255; g = 180; b = 180; outputBitmapData.setPixel(x, y, (r<<16) + (g<<8) + b); } } outputBitmapData.unlock(); var fps:Number = 1.0/((getTimer() - timer) / 1000.0); frameTimeTxt.text = "fps: " + int(fps); } } }