BitmapData Frame Texture

[SWF(width = 800, height = 600)]
var circle:Shape = new Shape();
var radius:Number = 4;
var diameter:Number = radius * 2;
var diam4:Number = diameter * 4;
with(circle.graphics) beginFill(0x000000), drawCircle(diameter,diameter,radius);
circle.filters = [new BlurFilter(5, 5, 2)];

var currFrame:Frame;

// populate the linked list
generateAnimation();

var animationNum:int = 8000;
var animation:Vector.<Frame> = new Vector.<Frame>();
var locs:Vector.<Point> = new Vector.<Point>();
// populate locs and animation
while(animation.length < animationNum){
       currFrame = currFrame.next;
       animation.push(currFrame);
       locs.push(new Point(Math.random() * stage.stageWidth - radius,
                           Math.random() * (stage.stageHeight+diam4) - diam4));
}

var rect:Rectangle = animation[0].bitmap.rect;
var bottom:Number = stage.stageHeight + rect.height;
var top:Number = -rect.height;

var canvas:BitmapData = new
BitmapData(stage.stageWidth,stage.stageHeight,false, 0x000000);
addChild(new Bitmap(canvas));

addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
       // clear the canvas
       canvas.fillRect(canvas.rect, 0x222222);
       // draw the current frame
       for (var i:int = 0; i<animationNum; i++){
               var ani:Frame = animation[i];
			   var pnt:Point = locs[i];
               canvas.copyPixels(ani.bitmap, rect, pnt, null, null, true);
               // get the next frame of the animation
			   pnt.y += 1;
			   if (pnt.y > bottom){
				   pnt.y = top;
			   }
               animation[i] = ani.next;
       }

}

// generate and capture 40 bitmaps by altering the colorTransform of
 
function generateAnimation():void{
       var channel:uint = 0;
       var ct:ColorTransform = new ColorTransform();
       var increase:Boolean = true;
       var firstFrame:Frame;
       var pFrame:Frame;
       for (var i:int = 0; i<40; i++){
               if (increase){
                  channel += 10.25;
                  if (channel > 200){
                         increase = false;
                  }
               }else{
                  channel -= 10;
               }
               ct.color = channel << 16 | channel << 8 | channel;
               circle.transform.colorTransform = ct;
			   
               // populate linked list
               currFrame = capture(circle);
               if (pFrame){
                  pFrame.next = currFrame;
               }
               if (i == 0){
                  firstFrame = currFrame;
               }
               pFrame = currFrame;
       }
       // close the list
       currFrame.next = firstFrame;
       currFrame = firstFrame;
}

// create the Frame instance and draw the circle to it
// preserving the colorTransform information
function capture(target:Shape):Frame{
       var frame:Frame = new Frame();
       frame.bitmap = new BitmapData(target.width*2, target.height*2, true, 0x000000000);
       frame.bitmap.draw(target, target.transform.matrix, target.transform.colorTransform);
       return frame;
}

This is a variation on the last post. It captures 40 small bitmaps of a blurred circle fading in and out and then draws 8000 of them to the stage.


Have a look at the swf…

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *