Triangular Numbers

Actionscript:
  1. [SWF(width = 500, height = 500)]
  2.  
  3. var txt:TextField = TextField(addChild(new TextField()));
  4. txt.defaultTextFormat = new TextFormat("_sans", 4);
  5. txt.width = stage.stageWidth;
  6. txt.height = stage.stageHeight+4;
  7. txt.z = -1;
  8. txt.x = stage.stageWidth
  9. txt.rotation = 90;
  10. var count:int = 0;
  11. addEventListener(Event.ENTER_FRAME, onLoop);
  12. function onLoop(evt:Event):void{
  13.      count++;
  14.      txt.appendText(triangular(count).toString(2) + "\n");
  15.      txt.scrollV= txt.maxScrollV;
  16. }
  17. function triangular(n:int):int{
  18.        return (n * (n + 1)) / 2;
  19. }

Calculate some triangular numbers... (n * (n + 1)) / 2....

Check out the swf on wonderfl

This entry was posted in Math, misc and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*