{"id":223,"date":"2009-03-18T00:00:24","date_gmt":"2009-03-18T07:00:24","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=981"},"modified":"2009-03-18T00:00:24","modified_gmt":"2009-03-18T07:00:24","slug":"circle-of-particles-2","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=223","title":{"rendered":"Circle of Particles #2"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 400, height = 400)];\r\nvar canvas:BitmapData = new BitmapData(400,400, false, 0x000000);\r\nvar eraser:BitmapData = new BitmapData(400,400, true, 0x11000000);\r\naddChild(new Bitmap(canvas));\r\n\r\nvar particles:Array = new Array();\r\nfor (var i:int = 0; i &lt; 500; 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\tvar ang:Number;\r\n\treturn function():void {\r\n\t\t\t  x += vx;\r\n\t\t      y += vy;\r\n\t\t      dx = 200 - x;\r\n\t\t      dy=  200 - y;\r\n\t\t\t   if (Math.sqrt((dx * dx) + (dy * dy)) &gt; 130){\r\n\t\t\t\tang = Math.atan2(dy, dx) \/ Math.PI * 180;\r\n\t\t\t\t vx = Math.cos(ang);\r\n\t\t\t\t vy = Math.sin(ang);\r\n\t\t\t   }\r\n\t\t       canvas.setPixel(x, y, 0xFFFFFF);\r\n\t}\r\n}\r\n<\/pre>\n<p>This is an interesting variation on yesterdays post. The result will looks like this&#8230;<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/circle_of_particles2.html\" target=\"blank\"><br \/>\nClick to view swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.actionsnippet.com\/imgs\/circle_particles.jpg\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/circle_of_particles2.swf&quot;,&quot;title&quot;:&quot;circle of particles2&quot;,&quot;width&quot;:400,&quot;height&quot;:400,&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\">: circle of particles2<\/span><\/button><\/span><\/p>\n<p>I also decided to do a processing port of this with 3,000 particles:<\/p>\n<p><a href=\"https:\/\/actionsnippet.com\/processing\/cofp.html\" target=\"blank\">Processing Version<\/a><\/p>\n<p>The processing version eventually evolved into this:<br \/>\n<a href=\"http:\/\/www.flickr.com\/photos\/shapevent\/3356781763\/sizes\/l\/\" target=\"blank\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/farm4.static.flickr.com\/3137\/3356781763_1d2db6515f.jpg\" \/><br \/>\nClick for enlarged version&#8230;<br \/>\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 400, height = 400)]; var canvas:BitmapData = new BitmapData(400,400, false, 0x000000); var eraser:BitmapData = new BitmapData(400,400, true, 0x11000000); addChild(new Bitmap(canvas)); var particles:Array = new Array(); for (var i:int = 0; i &lt; 500; 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; [&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,26],"tags":[3,4,123],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-bitmapdata","category-motion","category-setpixel","tag-actionscript","tag-flash","tag-processing"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/223","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=223"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}