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
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:
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.