{"id":100,"date":"2008-11-21T00:00:28","date_gmt":"2008-11-21T07:00:28","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=224"},"modified":"2008-11-21T00:00:28","modified_gmt":"2008-11-21T07:00:28","slug":"10000-copypixels","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=100","title":{"rendered":"10,000 Transparent Sprites"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nstage.frameRate = 30;\r\n\r\nvar imageNum:int = 10000;\r\nvar point:Point = new Point(0,0);\r\nvar s:Sprite = new Sprite();\r\ns.graphics.beginFill(0xCCCCCC);\r\ns.graphics.lineStyle(0,0x000000);\r\ns.graphics.drawCircle(3,3,3);\r\ns.alpha = .1;\r\n\r\nvar nested:Sprite = new Sprite();\r\nnested.addChild(s);\r\nvar image:BitmapData = new BitmapData(s.width, s.height, true, 0x00000000);\r\nimage.draw(nested);\r\n\r\nvar canvas:BitmapData = new BitmapData(400,400, true, 0xFFFFFFFF);\r\naddChild(new Bitmap(canvas));\r\n\r\nvar xPos:Array = new Array();\r\nvar yPos:Array = new Array();\r\nfor (var i:int = 0; i&lt;imageNum; i++) {\r\n\txPos.push(Math.random()*400);\r\n\tyPos.push(Math.random()*400);\r\n}\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tcanvas.fillRect(new Rectangle(0,0,400,400), 0xFFFFFFFF);\r\n\tvar div:Number;\r\n\tfor (var i:int = 0; i&lt;imageNum; i++) {\r\n\t\tdiv  = (i \/ 100)+2;\r\n\t\txPos&#x5B;i] += (mouseX - xPos&#x5B;i])\/div;\r\n\t\tyPos&#x5B;i] += (mouseY - yPos&#x5B;i])\/div;\r\n\t\tpoint.x = xPos&#x5B;i];\r\n\t\tpoint.y = yPos&#x5B;i];\r\n\t\tcanvas.copyPixels(image, image.rect, point, null, null, true);\r\n\t}\r\n}\r\n<\/pre>\n<p>This is from my <a href=\"http:\/\/www.shapevent.com\/\">other blog<\/a> but I figured it was worth posting here. It draws 10&#8217;000 transparent circles that each follow the mouse at different speeds. This is achieved using copyPixels().<\/p>\n","protected":false},"excerpt":{"rendered":"<p>stage.frameRate = 30; var imageNum:int = 10000; var point:Point = new Point(0,0); var s:Sprite = new Sprite(); s.graphics.beginFill(0xCCCCCC); s.graphics.lineStyle(0,0&#215;000000); s.graphics.drawCircle(3,3,3); s.alpha = .1; var nested:Sprite = new Sprite(); nested.addChild(s); var image:BitmapData = new BitmapData(s.width, s.height, true, 0x00000000); image.draw(nested); var canvas:BitmapData = new BitmapData(400,400, true, 0xFFFFFFFF); addChild(new Bitmap(canvas)); var xPos:Array = new Array(); var yPos:Array = [&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,13],"tags":[3,63,4],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-motion","tag-actionscript","tag-copypixels","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/100","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=100"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}