{"id":242,"date":"2009-04-04T09:44:26","date_gmt":"2009-04-04T16:44:26","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1109"},"modified":"2009-04-04T09:44:26","modified_gmt":"2009-04-04T16:44:26","slug":"bitmapdata-snapshot-grid","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=242","title":{"rendered":"BitmapData Snapshot Grid"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=600,height=650)]\r\nvar canvas:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,300,false,0xCCCCCC),&quot;auto&quot;,true))).bitmapData;\r\nvar stills:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,380,false,0xAAAAAA),&quot;auto&quot;,true))).bitmapData;\r\ngetChildAt(1).y=300;\r\n\r\nvar c:Shape = new Shape();\r\nvar m:Matrix = new Matrix();\r\nm.createGradientBox(40, 40, 0, 0, 0);\r\nc.graphics.beginGradientFill(GradientType.RADIAL, &#x5B;0xCC0000, 0xCC0000],  &#x5B;1, 0], &#x5B;0, 255], m);\r\nc.graphics.drawCircle(20,20,20);\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tc.x=mouseX-c.width\/2;\r\n\tc.y=mouseY-c.height\/2;\r\n\tcanvas.draw(c, c.transform.matrix);\r\n}\r\n\r\nvar spacing:Number = 10;\r\nvar cols:Number = 4;\r\nvar max:Number = cols * cols;\r\nvar size:Number = 1\/(canvas.width\/((canvas.width \/ cols) - spacing));\r\nvar st:Matrix = new Matrix();\r\nst.scale(size, size);\r\nvar w:Number = canvas.width * st.d  + spacing;\r\nvar h:Number = canvas.height * st.d + spacing;\r\nvar timer:Timer=new Timer(500);\r\ntimer.start();\r\ntimer.addEventListener(TimerEvent.TIMER, onCapture);\r\nfunction onCapture(evt:TimerEvent):void {\r\n\tvar inc:int = timer.currentCount - 1;\r\n\tst.tx = (inc% cols) * w+ spacing \/ 2;\r\n\tst.ty = int(inc \/ cols) * h + spacing;\r\n\tstills.draw(canvas, st);\r\n\tif (timer.currentCount==max) {\r\n\t\ttimer.reset();\r\n\t\ttimer.start();\r\n\t}\r\n}\r\n<\/pre>\n<p>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&#8230;<\/p>\n<p>You&#8217;ll need to move your mouse over the large canvas bitmap (drawing to it) to see anything&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=600,height=650)] var canvas:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,300,false,0xCCCCCC),&quot;auto&quot;,true))).bitmapData; var stills:BitmapData=Bitmap(addChild(new Bitmap(new BitmapData(600,380,false,0xAAAAAA),&quot;auto&quot;,true))).bitmapData; getChildAt(1).y=300; var c:Shape = new Shape(); var m:Matrix = new Matrix(); m.createGradientBox(40, 40, 0, 0, 0); c.graphics.beginGradientFill(GradientType.RADIAL, &#x5B;0xCC0000, 0xCC0000], &#x5B;1, 0], &#x5B;0, 255], m); c.graphics.drawCircle(20,20,20); addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { c.x=mouseX-c.width\/2; c.y=mouseY-c.height\/2; canvas.draw(c, c.transform.matrix); } var spacing:Number = 10; var cols:Number = 4; var max:Number = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[3,4],"class_list":["post-242","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/242\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}