{"id":430,"date":"2009-10-20T12:50:44","date_gmt":"2009-10-20T19:50:44","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2325"},"modified":"2009-10-20T12:50:44","modified_gmt":"2009-10-20T19:50:44","slug":"triangular-numbers","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=430","title":{"rendered":"Triangular Numbers"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 500, height = 500)]\r\n \r\nvar txt:TextField = TextField(addChild(new TextField()));\r\ntxt.defaultTextFormat = new TextFormat(&quot;_sans&quot;, 4);\r\ntxt.width = stage.stageWidth;\r\ntxt.height = stage.stageHeight+4;\r\ntxt.z = -1;\r\ntxt.x = stage.stageWidth\r\ntxt.rotation = 90;\r\nvar count:int = 0;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void{\r\n     count++;\r\n\t txt.appendText(triangular(count).toString(2) + &quot;n&quot;);\r\n\t txt.scrollV= txt.maxScrollV;\r\n}\r\nfunction triangular(n:int):int{\r\n       return (n * (n + 1)) \/ 2;\r\n}\r\n<\/pre>\n<p>Calculate some triangular numbers&#8230; (n * (n + 1)) \/ 2&#8230;.<\/p>\n<p><a href=\"http:\/\/wonderfl.net\/code\/7c13e9a1671456426b5d8297bd2ab0d4bab0a047\">Check out the swf on wonderfl<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 500, height = 500)] var txt:TextField = TextField(addChild(new TextField())); txt.defaultTextFormat = new TextFormat(&quot;_sans&quot;, 4); txt.width = stage.stageWidth; txt.height = stage.stageHeight+4; txt.z = -1; txt.x = stage.stageWidth txt.rotation = 90; var count:int = 0; addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void{ count++; txt.appendText(triangular(count).toString(2) + &quot;n&quot;); txt.scrollV= txt.maxScrollV; } function triangular(n:int):int{ return (n * (n + 1)) \/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121,94],"tags":[3,14,4],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-math","category-misc","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/430","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=430"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}