Animator
About Animator
Animator is a program that allows you to draw simple animated 2D vector graphics without having to know the intricate APIs of more sophisticated vector libs. You don't have to link with anything: animator reads drawing commands from its STDIN.
Optionally, Animator can describe mouse and keyboard events on its STDOUT, so interactive graphics may be made.
Animator is written in C and depends only on SDL. It can also draw using OpenGL, but GL support is optional both at compile and run time.
Animator might be useful together with software like Plumb.
Download
Source code is available from Subversion:
$ svn co svn://repo.hu/animator/trunk animator
i386 and amd64 Debian packages are available from the repo.hu Debian repository.
There is now a package for Arch Linux, thanks to AndreasBWagner.
Command Line
Animator takes no file arguments, input is always read from STDIN.
The following command line arguments are accepted:
- -h - display help
- -x N - set horizontal resolution (default 640)
- -y N - set vertical resolution (default 480)
- -D bpp - force color depth (bits per pixel)
- -k - disable keepalive, exit on EOF on STDIN (keepalive is enabled by default)
- -e - enable event reporting (disabled by default)
- -a - do not enforce aspect ratio (enforced by default)
- -g - enable OpenGL graphics (when compiled in; even so, disabled by default)
- -d head - save all frames as headXXXX.png (disables OpenGL)
- -q - quit Animator when Q is pressed
- -C - don't clear screen on new frame (disables OpenGL)
- -R - like -C, but allows resize
Input Syntax
Input is freeform, tokens are separated by whitespace.
Text starting with the ! character is ignored until EOL.
String constants can be given without quotes if they don't collide with keywords (and they're a single word); otherwise, they should be surrounded with double quotes ". Double quotes and backslashes can be escaped with backslash. Special characters \n \t \r \b \f are supported.
General Commands
- quit - shutdown program
- keepalive on|off - control whether to keep processing events after EOF on STDIN. Enabled by default
- events on|off - control event reporting. Disabled by default. When enabled, the current transformation matrix is saved as the event transformation matrix. Subsequent event coordinates will be reported in this coordinate system.
- resize width height - resize drawing window to a specific resolution
- warp X Y - move (warp) the mouse pointer to the specified position (given in the current coordinate system, not the event coordinate system). Will generate a MOTION event.
- warp area name - move (warp) the mouse pointer to an arbitrary point of the given area. Will generate a MOTION event.
- echo string - write the string (plus a newline) to STDOUT
- title string - set window title
Frame Management
- frame - use this at the beginning of a frame. Drawing color is set to black, line thickness is set to 1, dash pattern is set to 0xffff, but current transformations/matrices are preserved.
- flush - use this at the end of a frame. Draws current frame in the window. Can be invoked any time to refresh the window, even in the middle of frames.
- screenshot filename - equivalent to flush, but also saves the frame as filename (PNG format). Not supported in GL mode.
- sleep N - sleep N seconds (even event handling stops for this period...)
- flushdelay s - flush; then sleep, as much as to keep an even frame rate of one frame per s seconds; then (if event reporting is enabled) emit a FLUSHDELAY dt event, where dt is the amount of time to advance your app state by, in seconds. Best used with small s values (such as 0.0166666 for 60 fps).
- aspect on|off - enable/disable enforcing aspect radio (enabled by default)
- bg color - set background color - the color is given in the same form as with the color command. The default background is white.
Transformations
Initial coordinate system is left edge to right edge -1 .. 1, bottom edge to top edge -1 .. 1. Transformation matrices are kept on a stack; the top matrix of the stack is the active one.
- rotate angle - apply rotation, angle degrees counter-clockwise
- scale x [y] - scale current matrix, by x factor horizontally and y factor vertically. Giving y is optional, it defaults to x if omitted.
- shift x y - apply a translation, by x horizontally and y vertically
- mult 9xN - multiply current matrix with an arbitrary matrix - 9 numbers given in row-major order
- push - create a copy of the current transformation matrix and push it on the stack.
- pop - pop off the topmost element of the stack
- ident - load the identity matrix
Drawing
- color color - set drawing color - see color formatting
- alpha alpha - set alpha (transparency); goes from 0 (invisible) to 1 (opaque)
- thick number - set line thickness (applies to line, arrow, rect, lines, circle commands). Line thickness is given in pixels, and no transformations apply to it.
- dash 0xffff - set dash pattern (applies to the same commands as thick). For each pixel, 1 bits are drawn, 0 bits are not
- dot x y - draw a single pixel
- line x1 y1 x2 y2 - draw a line
- arrow x1 y1 x2 y2 - draw a line, with an arrowhead at x2,y2
- rect x y width height - draw a rectangle of size width * height, between x, x+width; y, y+height
- rect x1 y1 - x2 y2 - a variation on rect, draw rectangle between x1, x2; y1, y2
- fillrect x y width height - like rect, but fill it
- fillrect x1 y1 - x2 y2 - a variation on fillrect
- text [left|center|right bottom|center|top] x y text - draw text, at x,y; alignment is optional, default is center center
- lines x1 y1 x2 y2 [x3 y3]... - draw a line of multiple connected segments
- poly x1 y1 x2 y2 x3 y3 [x4 y4]... - draw a filled polygon
- circle x y r verts - draw a circle, with the given number of vertices, centered at x,y
- fillcircle x y r verts - like circle, but fill it
Colors
Colors can be specified in multiple ways:
- name - named colors (such as "black")
- #rrggbb - hexadecimal form, 0-255
- #rgb - hexadecimal form, each digit is duplicated
- #gg - grayscale hexadecimal, 0-255
- #g - grayscale hexadecimal, digit is duplicated
- red green blue - 3 floating point numbers, 0.0 - 1.0
- gray - 1 floating point number (grayscale), 0.0 - 1.0
Areas
Areas are used for event reporting. These are named polygon boundaries, the names of which are printed when events occur within their bounds.
- area name x1 y1 x2 y2 x3 y3 [x4 y4]... - defines a new Area, or redefines an existing one
- delarea name - deletes an Area
- killareas - deletes all Areas
Having many Areas doesn't cause a slowdown when processing mouse events. However, defining and redefining
Areas carries a performance penalty (comparable to rendering the corresponding polygon). Additionally,
the definition penalty is repeated for all Areas when the screen is resized.
In short, moving/redefining lots of Areas often won't be particularly efficient.
Macros
- macro name - start recording macro
- endmacro - end recording macro
- invoke name - execute macro
- invoke X Y name - equivalent to: push; shift by X,Y; execute macro; pop
- forget - forget all macros
Not all commands are allowed inside macro bodies; basically only drawing and matrix commands are allowed. This is the full list:
color alpha thick dash dot line arrow rect fillrect text lines poly circle fillcircle push pop mult rotate scale shift ident invoke area delarea
Empty macro bodies are not allowed.
Executing a macro is equivalent to executing the instructions in it. Recording a macro doesn't execute the instructions in it right away; the macro has to be invoked for that.
Macros can be redefined by recording a new macro of the same name. Macros are looked up each time they're invoked, so if a macro is redefined, its meaning will change in any other macro that invokes it.
Recursive macros will do exactly what you expect - crash animator, that is.
Event Output
When event reporting is turned on, a description of each event is written to STDOUT, one per line. Coordinates in events are written in the current coordinate system seen at the time of the last events on command.
Reported Event Types
For PRESS, RELEASE, and MOTION, the names of the Areas that contain the mouse pointer are printed,
separated by spaces.
mod_mask is a bitmask integer, describing which modifier keys are currently pressed. Here's the value table:
NONE = 0x0000,
LSHIFT= 0x0001,
RSHIFT= 0x0002,
LCTRL = 0x0040,
RCTRL = 0x0080,
LALT = 0x0100,
RALT = 0x0200,
LMETA = 0x0400,
RMETA = 0x0800,
NUM = 0x1000,
CAPS = 0x2000,
MODE = 0x4000
unicode is an integer: the unicode character the current keypress represents (might be 0 if no character can be associated)
keyname is the name of the pressed key, as reported by SDL_GetKeyName. A list may be seen here (the Common name column). Note that the names may contain spaces.
Author
Copyright (C) 2009-2010 Máté Nagy <mnagy AT port70.net>
Animator is licensed under the GNU General Public License Version 2 (available in the file COPYING) or any later version.
Home page: http://repo.hu/projects/animator