Triangular Numbers
/**
* Copyright shapevent ( http://wonderfl.net/user/shapevent )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hHDR
*/
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
[SWF(width = 500, height = 500)]
public class Triangular extends MovieClip {
private var txt:TextField;
private var count:int;
public function Triangular(){
txt = TextField(addChild(new TextField()));
txt.defaultTextFormat = new TextFormat("_sans", 4);
txt.width = stage.stageWidth;
txt.height = stage.stageHeight+4;
txt.z = -1;
txt.x = stage.stageWidth
txt.rotation = 90;
count = 0;
addEventListener(Event.ENTER_FRAME, onLoop);
}
// private methods
private function onLoop(evt:Event):void{
count++;
txt.appendText(triangular(count).toString(2) + "\n");
txt.scrollV= txt.maxScrollV;
}
private function triangular(n:int):int{
return (n * (n + 1)) / 2;
}
}
}