BitmapData Snapshot Grid

Actionscript:
  1. [SWF(width=600,height=650)]
  2. var canvas:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,300,false,0xCCCCCC),"auto",true))).bitmapData;
  3. var stills:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,380,false,0xAAAAAA),"auto",true))).bitmapData;
  4. getChildAt(1).y=300;
  5.  
  6. var c:Shape = new Shape();
  7. var m:Matrix = new Matrix();
  8. m.createGradientBox(40, 40, 0, 0, 0);
  9. c.graphics.beginGradientFill(GradientType.RADIAL, [0xCC0000, 0xCC0000],  [1, 0], [0, 255], m);
  10. c.graphics.drawCircle(20,20,20);
  11.  
  12. addEventListener(Event.ENTER_FRAME, onLoop);
  13. function onLoop(evt:Event):void {
  14.     c.x=mouseX-c.width/2;
  15.     c.y=mouseY-c.height/2;
  16.     canvas.draw(c, c.transform.matrix);
  17. }
  18.  
  19. var spacing:Number = 10;
  20. var cols:Number = 4;
  21. var max:Number = cols * cols;
  22. var size:Number = 1/(canvas.width/((canvas.width / cols) - spacing));
  23. var st:Matrix = new Matrix();
  24. st.scale(size, size);
  25. var w:Number = canvas.width * st.d  + spacing;
  26. var h:Number = canvas.height * st.d + spacing;
  27. var timer:Timer=new Timer(500);
  28. timer.start();
  29. timer.addEventListener(TimerEvent.TIMER, onCapture);
  30. function onCapture(evt:TimerEvent):void {
  31.     var inc:int = timer.currentCount - 1;
  32.     st.tx = (inc% cols) * w+ spacing / 2;
  33.     st.ty = int(inc / cols) * h + spacing;
  34.     stills.draw(canvas, st);
  35.     if (timer.currentCount==max) {
  36.         timer.reset();
  37.         timer.start();
  38.     }
  39. }

Take snapshots of a given BitmapData and arrange them in a grid. I wrote this snippet quickly in response to a question so it could probably use a little clean up...

You'll need to move your mouse over the large canvas bitmap (drawing to it) to see anything...

This entry was posted in BitmapData and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*