{"id":104,"date":"2008-11-25T00:00:16","date_gmt":"2008-11-25T07:00:16","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=99"},"modified":"2008-11-25T00:00:16","modified_gmt":"2008-11-25T07:00:16","slug":"simple-particles","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=104","title":{"rendered":"Simple Particles"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nstage.frameRate = 30;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void{\r\n\tif (int(Math.random()*5)==1){\r\n\t  for (var i:int= 0; i&lt;10; i++) createParticle();\r\n\t}\r\n}\r\n\r\nfunction createParticle():void{\r\n\tvar s:MovieClip = new MovieClip();\r\n\ts.graphics.beginFill(0);\r\n\ts.graphics.drawCircle(0,0,Math.random()*10 + 2);\r\n\ts.velX = Math.random()*10-5\r\n\ts.velY =  Math.random()*10-5\r\n\ts.posX = s.x = 200;\r\n\ts.posY = s.y = 200;\r\n\taddChild(s);\r\n\ts.addEventListener(Event.ENTER_FRAME, onRunParticle);\r\n}\r\n\r\nfunction onRunParticle(evt:Event):void {\r\n\tvar s:MovieClip = MovieClip(evt.currentTarget);\r\n\ts.posX += s.velX;\r\n\ts.posY += s.velY;\r\n    s.scaleX = s.scaleY -=  .04;\r\n\tif (s.scaleX &lt; 0){\r\n\t\tremoveChild(s);\r\n\t\ts.removeEventListener(Event.ENTER_FRAME, onRunParticle);\r\n\t}\r\n\ts.x = s.posX;\r\n\ts.y = s.posY;\r\n}\r\n<\/pre>\n<p>Nothing special here. But my students are always asking me about this &#8211; in class I have them alter this code to make fire, water and abstract particle systems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>stage.frameRate = 30; addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void{ if (int(Math.random()*5)==1){ for (var i:int= 0; i&lt;10; i++) createParticle(); } } function createParticle():void{ var s:MovieClip = new MovieClip(); s.graphics.beginFill(0); s.graphics.drawCircle(0,0,Math.random()*10 + 2); s.velX = Math.random()*10-5 s.velY = Math.random()*10-5 s.posX = s.x = 200; s.posY = s.y = 200; addChild(s); s.addEventListener(Event.ENTER_FRAME, onRunParticle); } function onRunParticle(evt:Event):void { var s:MovieClip = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,23],"tags":[3,4,70,71],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-motion","category-random","tag-actionscript","tag-flash","tag-particle-system","tag-particles"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/104","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=104"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/104\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}