{"id":433,"date":"2009-10-31T10:24:41","date_gmt":"2009-10-31T17:24:41","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2349"},"modified":"2009-10-31T10:24:41","modified_gmt":"2009-10-31T17:24:41","slug":"bitmapdata-frame-texture","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=433","title":{"rendered":"BitmapData Frame Texture"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">&#x5B;SWF(width = 800, height = 600)]\r\nvar circle:Shape = new Shape();\r\nvar radius:Number = 4;\r\nvar diameter:Number = radius * 2;\r\nvar diam4:Number = diameter * 4;\r\nwith(circle.graphics) beginFill(0x000000), drawCircle(diameter,diameter,radius);\r\ncircle.filters = &#x5B;new BlurFilter(5, 5, 2)];\r\n\r\nvar currFrame:Frame;\r\n\r\n\/\/ populate the linked list\r\ngenerateAnimation();\r\n\r\nvar animationNum:int = 8000;\r\nvar animation:Vector.&lt;Frame&gt; = new Vector.&lt;Frame&gt;();\r\nvar locs:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;();\r\n\/\/ populate locs and animation\r\nwhile(animation.length &lt; animationNum){\r\n       currFrame = currFrame.next;\r\n       animation.push(currFrame);\r\n       locs.push(new Point(Math.random() * stage.stageWidth - radius,\r\n                           Math.random() * (stage.stageHeight+diam4) - diam4));\r\n}\r\n\r\nvar rect:Rectangle = animation&#x5B;0].bitmap.rect;\r\nvar bottom:Number = stage.stageHeight + rect.height;\r\nvar top:Number = -rect.height;\r\n\r\nvar canvas:BitmapData = new\r\nBitmapData(stage.stageWidth,stage.stageHeight,false, 0x000000);\r\naddChild(new Bitmap(canvas));\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n       \/\/ clear the canvas\r\n       canvas.fillRect(canvas.rect, 0x222222);\r\n       \/\/ draw the current frame\r\n       for (var i:int = 0; i&lt;animationNum; i++){\r\n               var ani:Frame = animation&#x5B;i];\r\n\t\t\t   var pnt:Point = locs&#x5B;i];\r\n               canvas.copyPixels(ani.bitmap, rect, pnt, null, null, true);\r\n               \/\/ get the next frame of the animation\r\n\t\t\t   pnt.y += 1;\r\n\t\t\t   if (pnt.y &gt; bottom){\r\n\t\t\t\t   pnt.y = top;\r\n\t\t\t   }\r\n               animation&#x5B;i] = ani.next;\r\n       }\r\n\r\n}\r\n\r\n\/\/ generate and capture 40 bitmaps by altering the colorTransform of\r\n \r\nfunction generateAnimation():void{\r\n       var channel:uint = 0;\r\n       var ct:ColorTransform = new ColorTransform();\r\n       var increase:Boolean = true;\r\n       var firstFrame:Frame;\r\n       var pFrame:Frame;\r\n       for (var i:int = 0; i&lt;40; i++){\r\n               if (increase){\r\n                  channel += 10.25;\r\n                  if (channel &gt; 200){\r\n                         increase = false;\r\n                  }\r\n               }else{\r\n                  channel -= 10;\r\n               }\r\n               ct.color = channel &lt;&lt; 16 | channel &lt;&lt; 8 | channel;\r\n               circle.transform.colorTransform = ct;\r\n\t\t\t   \r\n               \/\/ populate linked list\r\n               currFrame = capture(circle);\r\n               if (pFrame){\r\n                  pFrame.next = currFrame;\r\n               }\r\n               if (i == 0){\r\n                  firstFrame = currFrame;\r\n               }\r\n               pFrame = currFrame;\r\n       }\r\n       \/\/ close the list\r\n       currFrame.next = firstFrame;\r\n       currFrame = firstFrame;\r\n}\r\n\r\n\/\/ create the Frame instance and draw the circle to it\r\n\/\/ preserving the colorTransform information\r\nfunction capture(target:Shape):Frame{\r\n       var frame:Frame = new Frame();\r\n       frame.bitmap = new BitmapData(target.width*2, target.height*2, true, 0x000000000);\r\n       frame.bitmap.draw(target, target.transform.matrix, target.transform.colorTransform);\r\n       return frame;\r\n}\r\n<\/pre>\n<p>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.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/frame_texture.html\"><br \/>\nHave a look at the swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/linked_texture.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/frame_texture.swf&quot;,&quot;title&quot;:&quot;frame texture&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: frame texture<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;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 = &#x5B;new BlurFilter(5, 5, 2)]; var currFrame:Frame; \/\/ populate the linked list generateAnimation(); var animationNum:int = 8000; var animation:Vector.&lt;Frame&gt; = new Vector.&lt;Frame&gt;(); var locs:Vector.&lt;Point&gt; [&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,140,79],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-data-structures","category-vector"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/433","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=433"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}