peter nitsch.net

peternitsch.net

AS3 ANSI

AS3 ANSI

After some last minute cleanup, I posted my AS3 ANSI tools to Google Code (http://code.google.com/p/as3ansi/). The source is still beta, with a few ANS files failing to parse properly, however the routines are tight enough that people can start playing around with it.

I built two primary tools. The first, called AnsiParser, is an extended ASCII parser for reading ANS files. It's a display-independent event dispatcher that can be interfaced with any application built to handle drawing operations. The parser broadcasts two custom events: CursorEvent (which describes cursor movement), and GraphicsEvent (which describes foreground and background color changes).

The full list of events is shown here:

Actionscript:
  1. parser = new AnsiParser();
  2.            
  3. parser.addEventListener(Event.COMPLETE, handleComplete);
  4. parser.addEventListener(CursorEvent.CARRIAGE_RETURN, handleCarriageReturn);
  5. parser.addEventListener(CursorEvent.DRAW_CHARACTER, handleDrawCharacter);
  6. parser.addEventListener(CursorEvent.FORM_FEED, handleFormFeed);
  7. parser.addEventListener(CursorEvent.MOVE_BACKWARD, handleMoveBackward);
  8. parser.addEventListener(CursorEvent.MOVE_DOWN, handleMoveDown);
  9. parser.addEventListener(CursorEvent.MOVE_FORWARD, handleMoveForward);
  10. parser.addEventListener(CursorEvent.MOVE_UP, handleMoveUp);
  11. parser.addEventListener(CursorEvent.REPOSITION, handleReposition);
  12. parser.addEventListener(CursorEvent.RESTORE_POSITION, handleRestorePosition);
  13. parser.addEventListener(CursorEvent.SAVE_POSITION, handleSavePosition);
  14. parser.addEventListener(GraphicsEvent.BACKGROUND_COLOR_CHANGED, handleBackgroundColorChanged);
  15. parser.addEventListener(GraphicsEvent.FOREGROUND_COLOR_CHANGED, handleForegroundColorChanged);
  16.  
  17. parser.load("n4-67.ans");

The second tool, called AnsiViewer, uses Perfect DOS VGA 437 font (by Zeh Fernando) to generate Sprites or Bitmaps from ANS files parsed by AnsiParser. It's meant for Flex or ActionScript projects, but anyone wanting to use it in CS3 can add the font to their library and set the linkage in the CharacterFactory. I'm planning to release a simple CS3 port of this tool in the very near future.

AnsiViewer is used in the following way:

Actionscript:
  1. import net.peternitsch.ansi.viewer.AnsiViewer;
  2.       
  3. private var ansiViewer:AnsiViewer;
  4.       
  5. private function init():void {
  6.     ansiViewer = new AnsiViewer();
  7.     ansiViewer.addEventListener(Event.COMPLETE, handleComplete);
  8.     ansiViewer.load("n4-67.ans");
  9. }
  10.       
  11. private function handleComplete(e:Event):void {
  12.     var bitmap:Bitmap = ansiViewer.getBitmap();
  13.     addChild(bitmap);
  14. }

Like I've already mentioned, these tools are still very beta. I'm planning to clean them up, write proper documentation, and add more tools. I'd love to hear feedback, comments, or requests. These tools were meant as a homage to the ANSI Art scene by giving the community an easy AS3 kit they can build drawing editors, viewers, and who knows what with.

Check out the demo.

Category: AS3 ANSI

Tagged: , , , , , , ,

2 Responses

  1. [...] him to create as3ansi, an ANSI parsing and visualization code. There’s a lot more about that here, with some sample code to illustrate; his event-driven ANSI parsing code is awesome, considering [...]

  2. booch says:

    This is amazing! I would much prefer this tool to render score ansis on my website instead of the horrid java applet. Can I volunteer as a beta tester? :D

Leave a Reply