Zig Zag Binary ix2 & i/2

Actionscript:
  1. var txt:TextField = TextField(addChild(new TextField()));
  2. txt.text = "";
  3. txt.width = 190;
  4. txt.height = 400;
  5. txt.multiline = true;
  6.  
  7. var count:int = 1;
  8. function render():void{
  9.     var line = int(count).toString(2);
  10.     while(line.length <31){
  11.         line = "0" + line;
  12.     }
  13.     txt.appendText(line + "\n");
  14.     txt.scrollV= txt.maxScrollV;
  15. }
  16.  
  17. addEventListener(Event.ENTER_FRAME, onCountUp);
  18. function onCountUp(evt:Event):void {
  19.     count *= 2;
  20.     render();
  21.     if (count ==0x40000000){
  22.         removeEventListener(Event.ENTER_FRAME, onCountUp);
  23.         addEventListener(Event.ENTER_FRAME, onCountDown);
  24.     }
  25. }
  26. function onCountDown(evt:Event):void {
  27.     count /= 2;
  28.     render();
  29.     if (count ==1){
  30.         addEventListener(Event.ENTER_FRAME, onCountUp);
  31.         removeEventListener(Event.ENTER_FRAME, onCountDown);
  32.     }
  33. }

The above animates a zig zag pattern in a TextField.

This entry was posted in Math, string manipulation, strings. 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 *

*
*