{"id":222,"date":"2009-03-17T00:00:38","date_gmt":"2009-03-17T07:00:38","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=979"},"modified":"2009-03-17T00:00:38","modified_gmt":"2009-03-17T07:00:38","slug":"circle-of-particles","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=222","title":{"rendered":"Circle of Particles"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar canvas:BitmapData = new BitmapData(400,400, false, 0xFFFFFF);\r\naddChild(new Bitmap(canvas));\r\nvar eraser:BitmapData = new BitmapData(400,400, true, 0x33FFFFFF);\r\n\r\nvar particles:Array = new Array();\r\nfor (var i:int = 0; i &lt; 1000; i++){\r\n\tparticles.push(makeParticle());\r\n}\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tcanvas.copyPixels(eraser, eraser.rect, new Point(0,0), null, null, true);\r\n\tfor (var i:int = 0; i &lt; particles.length; i++){\r\n\t\tparticles&#x5B;i]();\r\n\t}\r\n}\r\n\r\nfunction makeParticle():Function {\r\n\tvar dx:Number, dy:Number;\r\n\tvar x:Number = 200;\r\n\tvar y:Number = 200;\r\n\tvar vx:Number = Math.random() * 4 - 2;\r\n\tvar vy:Number = Math.random() * 4 - 2;\r\n\treturn function():void {\r\n\t\t\t  x += vx;\r\n\t\t      y += vy;\r\n\t\t      dx = x - 200;\r\n\t\t      dy= y - 200;\r\n\t\t\t   if (Math.sqrt((dx * dx) + (dy * dy)) &gt; 100){\r\n\t\t\t\t vx *= -1;\r\n\t\t\t\t vy *= -1;\r\n\t\t\t   }\r\n\t\t       canvas.setPixel(x, y, 0x000000);\r\n\t}\r\n}\r\n<\/pre>\n<p>This creates a circular area filled with moving particles\/pixels. It makes use of yesterdays functional programming techniques.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var canvas:BitmapData = new BitmapData(400,400, false, 0xFFFFFF); addChild(new Bitmap(canvas)); var eraser:BitmapData = new BitmapData(400,400, true, 0x33FFFFFF); var particles:Array = new Array(); for (var i:int = 0; i &lt; 1000; i++){ particles.push(makeParticle()); } addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { canvas.copyPixels(eraser, eraser.rect, new Point(0,0), null, null, true); for (var i:int = 0; i &lt; particles.length; i++){ particles&#x5B;i](); } [&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,17,13,26],"tags":[3,4],"class_list":["post-222","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-functions","category-motion","category-setpixel","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/222","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=222"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/222\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}