Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC

ASCII Animation (Just for Fun)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
20 May 20023 min read 85.6K   1.4K   13   7
Draw and animate ASCII characters to a window using this COM object.

Introduction

Asciimation is short for ASCII animation. Kind of a poor man's DirectX or Window's GDI. Here, I present a small COM library for you creative types to try your hand at this new art form.

What's the Point?

There is none, I did this for fun. I was inspired by Star Wars Asciimation and thought, I could make that a little easier on would be ASCII artists.

The IAsciiAPI Interface Methods

C++
Initialize(DWORD hwnd, [out, retval] VARIANT_BOOL* bInitialized);
SetBackColor(int R, int G, int B);
SetBackMode(int nMode);
SetForeColor(int R, int G, int B);
GetWidth([out, retval] int* width);
GetHeight([out, retval] int* height);
ClearScreen();
DrawString(BSTR bstrString, int x, int y);
Circle(int x, int y, int radius, int step, short nAsciiCode, 
    VARIANT_BOOL bFilled);
Arc(int x, int y, int radius, int degfrom, int degto, int step, 
    short nAsciiCode, VARIANT_BOOL bFilled);
Rectangle(int left, int top, int right, int bottom, short nAsciiCode, 
    VARIANT_BOOL bFilled);
CharBlit(BSTR bstrCharArray, int Width, int Height, int DestX, 
    int DestY, short nAsciiMask);

Initialize

Send this method the HWND of the window to draw the Asciimation on. Without this, it has nowhere to draw to. I thought about making Asciimation a control, but I thought it would be better to make it more API like.

SetBackMode

Sets the nBackMode member variable which is used to set the background mode of the text (OPAQUE or TRANSPARENT).

SetBackColor

Sets the crBackColor member variable which is used to set the background color of the text.

SetForeColor

Sets the crForeColor member variable which is used to set the color of the text.

GetWidth

Returns the number of characters that will fit in the width of the window.

GetHeight

Returns the number of characters that will fit in the height of the window.

ClearScreen

Draws spaces across the width and height of the window using the current background mode and background color.

DrawString

Draws an array of character on the window at the given coordinates.

Circle

Draws a circle of characters, using the nAsciiCode parameter, with the center at (x,y) and a radius of radius. The step parameter will draw a broken circle, drawing characters only every step degrees. To fill the circle, set bFilled = VARIANT_TRUE, otherwise set it to VARIANT_FALSE.

Arc

Draws an arc of characters, using the nAsciiCode parameter, with the center at (x,y) and a radius of radius, from degfrom degrees to degto degrees. The step parameter will draw a broken arc, drawing characters only every step degrees.

Rectangle

Draws a rectangle of characters with corners at (left, top) - (right, bottom) using the nAsciiCode parameter. To fill the rectangle, set bFilled = VARIANT_TRUE, otherwise set it to VARIANT_FALSE.

CharBlit

Draw the bstrCharArray array of characters to the window at (DestX, DestY). All characters will display in a Width X Height rectangle except for nAsciiMask character, which will not be drawn at all.

Conclusion

If you found this code useful in any way, that's awesome! If not, too bad, but I hope you can have some fun with it.

Here are a couple of screen shots from the demo project:

Image 1

Image 2

If you have ideas on improving or adding methods to Asciimation, feel free to drop me an e-mail or a message here, or take the initiative and modify the code yourself.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Software Developer (Senior)
United States United States
I have been a professional developer since 1996. I live in Illinois, in the USA. I am married and have four children.

Comments and Discussions

 
Generalmissing file Pin
Chris Losinger21-May-02 10:48
professionalChris Losinger21-May-02 10:48 
GeneralRe: missing file Pin
Jason Henderson21-May-02 10:55
Jason Henderson21-May-02 10:55 
GeneralRe: missing file Pin
lucy21-May-02 11:43
lucy21-May-02 11:43 
why the project I downloaded always fail at CAsciimationtestDlg::OnInitDialog()
{
...
hr = pAsciiAPI.CreateInstance("Asciimation.AsciiAPI");
...
}
the hr is a negative number.

Confused | :confused:
GeneralRe: missing file Pin
lucy21-May-02 11:46
lucy21-May-02 11:46 
GeneralRe: missing file Pin
Christian Graus21-May-02 16:29
protectorChristian Graus21-May-02 16:29 
GeneralRe: missing file Pin
Jason Henderson21-May-02 16:43
Jason Henderson21-May-02 16:43 
GeneralRe: missing file Pin
lucy22-May-02 2:44
lucy22-May-02 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.